public GarmentInvoiceController(IServiceProvider serviceProvider, IMapper mapper, IGarmentInvoice facade, IGarmentDeliveryOrderFacade DOfacade) { this.serviceProvider = serviceProvider; this.mapper = mapper; this.facade = facade; this.DOfacade = DOfacade; this.identityService = (IdentityService)serviceProvider.GetService(typeof(IdentityService)); }
public GarmentInternNoteController(IServiceProvider serviceProvider, IMapper mapper, IGarmentInternNoteFacade facade, IGarmentDeliveryOrderFacade deliveryOrderFacade, IGarmentInvoice invoiceFacade) { this.serviceProvider = serviceProvider; this.mapper = mapper; this.facade = facade; this.identityService = (IdentityService)serviceProvider.GetService(typeof(IdentityService)); this.deliveryOrderFacade = deliveryOrderFacade; this.invoiceFacade = invoiceFacade; }
public static MemoryStream Generate(GarmentCorrectionNote model, IServiceProvider serviceProvider, int clientTimeZoneOffset = 7, string userName = "") { IGarmentDeliveryOrderFacade garmentDeliveryOrderFacade = (IGarmentDeliveryOrderFacade)serviceProvider.GetService(typeof(IGarmentDeliveryOrderFacade)); IGarmentInvoice garmentInvoiceFacade = (IGarmentInvoice)serviceProvider.GetService(typeof(IGarmentInvoice)); Document document = new Document(PageSize.A4, 10, 10, 10, 10); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); Font header_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); PdfPCell cellLeftNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellCenterNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellCenterTopNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_TOP }; PdfPCell cellRightNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellJustifyNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED }; PdfPCell cellJustifyAllNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED_ALL }; PdfPCell cellCenter = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellRight = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellLeft = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; var deliveryOrder = garmentDeliveryOrderFacade.ReadById((int)model.DOId); var invoice = garmentInvoiceFacade.ReadByDOId((int)model.DOId); #region Header string addressString = "PT. DAN LIRIS\n" + "JL. Merapi No.23\n" + "Banaran, Grogol, Kab. Sukoharjo\n" + "Jawa Tengah 57552 - INDONESIA\n" + "PO.BOX 166 Solo 57100\n" + "Telp. (0271) 740888, 714400\n" + "Fax. (0271) 735222, 740777"; Paragraph addressParagraph = new Paragraph(8f, addressString, bold_font) { Alignment = Element.ALIGN_LEFT }; document.Add(addressParagraph); Paragraph headerParagraph = new Paragraph("NOTA KOREKSI PAJAK", header_font) { Alignment = Element.ALIGN_CENTER, SpacingAfter = 15f }; document.Add(headerParagraph); #endregion #region Identity PdfPTable tableIdentity = new PdfPTable(2); tableIdentity.SetWidths(new float[] { 1f, 1f }); PdfPTable tableIdentityLeft = new PdfPTable(2); tableIdentityLeft.SetWidths(new float[] { 3f, 5f }); cellLeftNoBorder.Phrase = new Phrase("No. Nota Koreksi", normal_font); tableIdentityLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {model.CorrectionNo}", normal_font); tableIdentityLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No. Nota Pajak", normal_font); tableIdentityLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {model.NKPN}", normal_font); tableIdentityLeft.AddCell(cellLeftNoBorder); PdfPTable tableIdentityRight = new PdfPTable(2); cellLeftNoBorder.Phrase = new Phrase("Kode Supplier", normal_font); tableIdentityRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {model.SupplierCode}", normal_font); tableIdentityRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Nama Supplier", normal_font); tableIdentityRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {model.SupplierName}", normal_font); tableIdentityRight.AddCell(cellLeftNoBorder); PdfPCell cellIdentityLeft = new PdfPCell(tableIdentityLeft) { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; tableIdentity.AddCell(cellIdentityLeft); PdfPCell cellIdentityRight = new PdfPCell(tableIdentityRight) { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; tableIdentity.AddCell(cellIdentityRight); PdfPCell cellIdentity = new PdfPCell(tableIdentity); tableIdentity.ExtendLastRow = false; tableIdentity.SpacingAfter = 5f; document.Add(tableIdentity); #endregion #region TableContent var columnHeaders = new List <string> { "No. Surat Jalan", "Tgl. Surat Jalan", "Tgl. Jatuh Tempo", "No. Invoice", "Nama Barang", $"Total PPN ({model.CurrencyCode})" }; PdfPTable tableContent = new PdfPTable(columnHeaders.Count); tableContent.SetWidths(new float[] { 1.1f, 1.2f, 1f, 1f, 1.1f, 1.2f }); foreach (var columnName in columnHeaders) { cellCenter.Phrase = new Phrase(columnName, bold_font); tableContent.AddCell(cellCenter); } Dictionary <string, decimal> dictionaryUnitAmount = new Dictionary <string, decimal>(); var totalAmountPPH = 0m; foreach (var item in model.Items) { var deliveryOrderItem = deliveryOrder.Items.First(i => i.Details.Any(d => d.Id == item.DODetailId)); cellLeft.Phrase = new Phrase(deliveryOrder.DONo, normal_font); tableContent.AddCell(cellLeft); cellLeft.Phrase = new Phrase(deliveryOrder.DODate.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); tableContent.AddCell(cellLeft); cellLeft.Phrase = new Phrase(deliveryOrder.DODate.AddDays(deliveryOrderItem.PaymentDueDays).ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); tableContent.AddCell(cellLeft); if (invoice != null) { cellLeft.Phrase = new Phrase(invoice.InvoiceNo, normal_font); tableContent.AddCell(cellLeft); } else { cellLeft.Phrase = new Phrase("", normal_font); tableContent.AddCell(cellLeft); } cellLeft.Phrase = new Phrase(item.ProductName, normal_font); tableContent.AddCell(cellLeft); decimal totalPPH; var convertdouble = Convert.ToDecimal(model.VatRate); totalPPH = (convertdouble / 100) * item.PricePerDealUnitAfter * item.Quantity; totalAmountPPH += totalPPH; cellRight.Phrase = new Phrase(totalPPH.ToString("n", new CultureInfo("id-ID")), normal_font); tableContent.AddCell(cellRight); } PdfPCell cellRightMerge = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5, Colspan = columnHeaders.Count - 1 }; cellRightMerge.Phrase = new Phrase($"Total PPN ({model.CurrencyCode})", normal_font); tableContent.AddCell(cellRightMerge); cellRight.Phrase = new Phrase(totalAmountPPH.ToString("n", new CultureInfo("id-ID")), normal_font); tableContent.AddCell(cellRight); cellRightMerge.Phrase = new Phrase("Total PPN (IDR)", normal_font); tableContent.AddCell(cellRightMerge); cellRight.Phrase = new Phrase((totalAmountPPH * (decimal)deliveryOrder.DOCurrencyRate).ToString("n", new CultureInfo("id-ID")), normal_font); tableContent.AddCell(cellRight); PdfPCell cellContent = new PdfPCell(tableContent); tableContent.ExtendLastRow = false; tableContent.SpacingAfter = 60f; document.Add(tableContent); #endregion #region TableSignature var signer = new List <string> { "Staff Pembelian", "Administrasi", "Keuangan", "Pembukuan" }; PdfPTable tableSignature = new PdfPTable(signer.Count); foreach (var columnName in signer) { cellCenter.Phrase = new Phrase(columnName, bold_font); tableSignature.AddCell(cellCenter); } for (int i = 0; i < signer.Count; i++) { cellCenter.Phrase = new Phrase("\n\n\n\n\n\n(Nama & Tanggal)", bold_font); tableSignature.AddCell(cellCenter); } PdfPCell cellSignature = new PdfPCell(tableSignature); // dont remove tableSignature.ExtendLastRow = false; tableSignature.SpacingAfter = 10f; document.Add(tableSignature); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { IGarmentInvoice invoiceFacade = validationContext == null ? null : (IGarmentInvoice)validationContext.GetService(typeof(IGarmentInvoice)); IGarmentDeliveryOrderFacade doFacade = validationContext == null ? null : (IGarmentDeliveryOrderFacade)validationContext.GetService(typeof(IGarmentDeliveryOrderFacade)); if (currency == null) { yield return(new ValidationResult("currency is required", new List <string> { "currency" })); } if (supplier == null) { yield return(new ValidationResult("Supplier is required", new List <string> { "supplier" })); } int itemErrorCount = 0; int detailErrorCount = 0; if (this.items == null || items.Count <= 0) { yield return(new ValidationResult("Item is required", new List <string> { "itemscount" })); } else { //Enhance Jason Sept 2021 List <string> arrNo = new List <string>(); foreach (var detailItem in items) { if (detailItem.garmentInvoice != null) { arrNo.Add(detailItem.garmentInvoice.invoiceNo); } } string itemError = "["; bool? prevUseIncomeTax = null; bool? prevUseVat = null; string paymentMethod = ""; long? IncomeTaxId = null; foreach (var item in items) { itemError += "{"; if (item.garmentInvoice == null || item.garmentInvoice.Id == 0) { itemErrorCount++; itemError += "garmentInvoice: 'No Garment Invoice selected', "; } else { //Enhance Jason Sept 2019 : Invoice No Validation //Check Duplicate Invoice No for 1 Invoice //if (arrNo.FindAll(e => e == item.garmentInvoice.invoiceNo).Count > 1) //{ // itemErrorCount++; // itemError += "garmentInvoice: 'there is duplication of invoiceNo " + item.garmentInvoice.invoiceNo + "', "; //} if (items.ToList().Where(x => x.garmentInvoice.invoiceNo == item.garmentInvoice.invoiceNo && x.garmentInvoice.invoiceDate == item.garmentInvoice.invoiceDate).Count() > 1) { itemErrorCount++; itemError += "garmentInvoice: 'there is duplication of invoiceNo " + item.garmentInvoice.invoiceNo + "', "; } //Check if Invoice No for Specific Supplier is Existed PurchasingDbContext purchasingDbContext = (PurchasingDbContext)validationContext.GetService(typeof(PurchasingDbContext)); var detailData = purchasingDbContext.GarmentInternNoteItems.Where(w => w.InvoiceId == item.garmentInvoice.Id && w.InvoiceDate == item.garmentInvoice.invoiceDate && w.IsDeleted == false).Select(s => new { s.Id, s.GarmentINId, s.InvoiceId, s.InvoiceNo }); if (detailData.ToList().Count > 0) { foreach (var itemDetail in detailData) { var headerData = purchasingDbContext.GarmentInternNotes.Where(w => w.Id == itemDetail.GarmentINId && w.SupplierId == supplier.Id && w.IsDeleted == false).Select(s => new { s.INNo }); if (headerData.ToList().Count > 0) { foreach (var itemHeader in headerData) { itemErrorCount++; itemError += "garmentInvoice: 'invoiceNo " + item.garmentInvoice.invoiceNo + " already existed on Intern Note No " + itemHeader.INNo.ToString() + "', "; } } } } var invoice = invoiceFacade.ReadById((int)item.garmentInvoice.Id); if (prevUseIncomeTax != null && prevUseIncomeTax != invoice.UseIncomeTax) { itemErrorCount++; itemError += "useincometax: 'UseIncomeTax harus sama', "; } prevUseIncomeTax = invoice.UseIncomeTax; if (prevUseVat != null && prevUseVat != invoice.UseVat) { itemErrorCount++; itemError += "usevat: 'UseVat harus sama', "; } prevUseVat = invoice.UseVat; if (IncomeTaxId != null && IncomeTaxId != invoice.IncomeTaxId) { itemErrorCount++; itemError += "incometax: 'Income Tax Harus Sama', "; } IncomeTaxId = invoice.IncomeTaxId; if (item.details == null || item.details.Count.Equals(0)) { itemErrorCount++; itemError += "detailscount: 'Details is required', "; } else { string detailError = "["; foreach (var detail in item.details) { detailError += "{"; var deliveryOrder = doFacade.ReadById((int)detail.deliveryOrder.Id); var invitem = invoice.Items.First(s => s.InvoiceId == item.garmentInvoice.Id); if (invitem != null) { if (paymentMethod != "" && paymentMethod != invitem.PaymentMethod) { detailErrorCount++; detailError += "paymentMethod: 'TermOfPayment Harus Sama', "; } paymentMethod = deliveryOrder.PaymentMethod; } detailError += "}, "; } detailError += "]"; if (detailErrorCount > 0) { itemErrorCount++; itemError += $"details: {detailError}, "; } } } itemError += "}, "; } itemError += "]"; if (itemErrorCount > 0) { yield return(new ValidationResult(itemError, new List <string> { "items" })); } } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { IGarmentInvoice invoiceFacade = validationContext == null ? null : (IGarmentInvoice)validationContext.GetService(typeof(IGarmentInvoice)); IGarmentDeliveryOrderFacade doFacade = validationContext == null ? null : (IGarmentDeliveryOrderFacade)validationContext.GetService(typeof(IGarmentDeliveryOrderFacade)); if (currency == null) { yield return(new ValidationResult("currency is required", new List <string> { "currency" })); } if (supplier == null) { yield return(new ValidationResult("Supplier is required", new List <string> { "supplier" })); } int itemErrorCount = 0; int detailErrorCount = 0; if (this.items == null || items.Count <= 0) { yield return(new ValidationResult("Item is required", new List <string> { "itemscount" })); } else { string itemError = "["; bool? prevUseIncomeTax = null; bool? prevUseVat = null; string paymentMethod = ""; foreach (var item in items) { itemError += "{"; if (item.garmentInvoice == null || item.garmentInvoice.Id == 0) { itemErrorCount++; itemError += "garmentInvoice: 'No Garment Invoice selected', "; } else { var invoice = invoiceFacade.ReadById((int)item.garmentInvoice.Id); if (prevUseIncomeTax != null && prevUseIncomeTax != invoice.UseIncomeTax) { itemErrorCount++; itemError += "useincometax: 'UseIncomeTax harus sama', "; } prevUseIncomeTax = invoice.UseIncomeTax; if (prevUseVat != null && prevUseVat != invoice.UseVat) { itemErrorCount++; itemError += "usevat: 'UseVat harus sama', "; } prevUseVat = invoice.UseVat; if (item.details == null || item.details.Count.Equals(0)) { itemErrorCount++; itemError += "detailscount: 'Details is required', "; } else { string detailError = "["; foreach (var detail in item.details) { detailError += "{"; var deliveryOrder = doFacade.ReadById((int)detail.deliveryOrder.Id); if (deliveryOrder != null) { if (paymentMethod != "" && paymentMethod != deliveryOrder.PaymentMethod) { detailErrorCount++; detailError += "paymentMethod: 'TermOfPayment Harus Sama', "; } paymentMethod = deliveryOrder.PaymentMethod; } detailError += "}, "; } detailError += "]"; if (detailErrorCount > 0) { itemErrorCount++; itemError += $"details: {detailError}, "; } } } itemError += "}, "; } itemError += "]"; if (itemErrorCount > 0) { yield return(new ValidationResult(itemError, new List <string> { "items" })); } } }