public async Task Should_Success_Get_Data_By_DOId() { var facade = new GarmentCorrectionNoteQuantityFacade(GetServiceProvider().Object, _dbContext(GetCurrentMethod())); GarmentCorrectionNote data = await dataUtil(facade, GetCurrentMethod()).GetTestData(USERNAME); var Response = facade.ReadByDOId((int)data.DOId); Assert.NotNull(Response); }
public async Task <int> Create(GarmentCorrectionNote garmentCorrectionNote, string user, int clientTimeZoneOffset = 7) { int Created = 0; using (var transaction = this.dbContext.Database.BeginTransaction()) { try { EntityExtension.FlagForCreate(garmentCorrectionNote, user, USER_AGENT); do { garmentCorrectionNote.CorrectionNo = CodeGenerator.Generate(); }while (dbSet.Any(m => m.CorrectionNo == garmentCorrectionNote.CorrectionNo)); garmentCorrectionNote.TotalCorrection = garmentCorrectionNote.Items.Sum(i => i.PriceTotalAfter - i.PriceTotalBefore); var garmentDeliveryOrder = dbContext.GarmentDeliveryOrders.First(d => d.Id == garmentCorrectionNote.DOId); garmentDeliveryOrder.IsCorrection = true; EntityExtension.FlagForUpdate(garmentDeliveryOrder, user, USER_AGENT); foreach (var item in garmentCorrectionNote.Items) { EntityExtension.FlagForCreate(item, user, USER_AGENT); var garmentDeliveryOrderDetail = dbContext.GarmentDeliveryOrderDetails.First(d => d.Id == item.DODetailId); if ((garmentCorrectionNote.CorrectionType ?? "").ToUpper() == "HARGA SATUAN") { garmentDeliveryOrderDetail.PricePerDealUnitCorrection = (double)item.PricePerDealUnitAfter; garmentDeliveryOrderDetail.PriceTotalCorrection = (double)item.PriceTotalAfter; } else if ((garmentCorrectionNote.CorrectionType ?? "").ToUpper() == "HARGA TOTAL") { garmentDeliveryOrderDetail.PriceTotalCorrection = (double)item.PriceTotalAfter; } EntityExtension.FlagForUpdate(garmentDeliveryOrderDetail, user, USER_AGENT); } dbSet.Add(garmentCorrectionNote); Created = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }
public async Task <GarmentCorrectionNote> GetNewData() { var garmentDeliveryOrder = await Task.Run(() => garmentDeliveryOrderDataUtil.GetTestData()); GarmentCorrectionNote garmentCorrectionNote = new GarmentCorrectionNote { CorrectionNo = "NK1234L", CorrectionType = "Jumlah", CorrectionDate = DateTimeOffset.Now, DOId = garmentDeliveryOrder.Id, DONo = garmentDeliveryOrder.DONo, SupplierId = garmentDeliveryOrder.SupplierId, SupplierCode = garmentDeliveryOrder.SupplierCode, SupplierName = garmentDeliveryOrder.SupplierName, Remark = "Remark", NKPH = "NKPH1234L", NKPN = "NKPN1234L", Items = new List <GarmentCorrectionNoteItem>() }; foreach (var item in garmentDeliveryOrder.Items) { foreach (var detail in item.Details) { garmentCorrectionNote.Items.Add( new GarmentCorrectionNoteItem { DODetailId = detail.Id, EPOId = item.EPOId, EPONo = item.EPONo, PRId = detail.PRId, PRNo = detail.PRNo, POId = detail.POId, POSerialNumber = detail.POSerialNumber, RONo = detail.RONo, ProductId = detail.ProductId, ProductCode = detail.ProductCode, ProductName = detail.ProductName, Quantity = (decimal)detail.QuantityCorrection, UomId = Convert.ToInt32(detail.UomId), UomIUnit = detail.UomUnit, }); } } return(garmentCorrectionNote); }
private string GenerateNKPH(string code, GarmentCorrectionNote garmentCorrectionNote) { string Year = garmentCorrectionNote.CorrectionDate.ToOffset(new TimeSpan(identityService.TimezoneOffset, 0, 0)).ToString("yy"); string Month = garmentCorrectionNote.CorrectionDate.ToOffset(new TimeSpan(identityService.TimezoneOffset, 0, 0)).ToString("MM"); string no = string.Concat(code, Year, Month); int Padding = 4; var lastData = dbSet.Where(w => (w.NKPH ?? "").StartsWith(no) && !w.IsDeleted).OrderByDescending(o => o.NKPH).FirstOrDefaultAsync().Result; int lastNoNumber = 0; if (lastData != null) { int.TryParse(lastData.NKPH.Substring(no.Length, lastData.NKPH.Length - no.Length), out lastNoNumber); } return(no + (lastNoNumber + 1).ToString().PadLeft(Padding, '0')); }
public async Task <string> GenerateNKPH(GarmentCorrectionNote model, int clientTimeZoneOffset) { DateTimeOffset dateTimeOffsetNow = DateTimeOffset.Now; string Month = dateTimeOffsetNow.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("MM"); string Year = dateTimeOffsetNow.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("yy"); string no = $"NKPH{Year}{Month}"; int Padding = 4; var lastNo = await this.dbSet.Where(w => w.NKPH.StartsWith(no) && !w.IsDeleted).OrderByDescending(o => o.NKPH).FirstOrDefaultAsync(); if (lastNo == null) { return(no + "1".PadLeft(Padding, '0')); } else { int lastNoNumber = Int32.Parse(lastNo.NKPH.Replace(no, "")) + 1; return(no + lastNoNumber.ToString().PadLeft(Padding, '0')); } }
public async Task <string> GenerateNo(GarmentCorrectionNote model, bool isImport, int clientTimeZoneOffset) { DateTimeOffset dateTimeOffsetNow = DateTimeOffset.Now; string Month = dateTimeOffsetNow.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("MM"); string Year = dateTimeOffsetNow.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("yy"); string Supplier = isImport ? "I" : "L"; string no = $"NK{Year}{Month}"; int Padding = 4; var lastNo = await this.dbSet.Where(w => w.CorrectionNo.StartsWith(no) && w.CorrectionNo.EndsWith(Supplier) && !w.IsDeleted).OrderByDescending(o => o.CorrectionNo).FirstOrDefaultAsync(); if (lastNo == null) { return(no + "1".PadLeft(Padding, '0') + Supplier); } else { int.TryParse(lastNo.CorrectionNo.Replace(no, "").Replace(Supplier, ""), out int lastno1); int lastNoNumber = lastno1 + 1; return(no + lastNoNumber.ToString().PadLeft(Padding, '0') + Supplier); } }
public async Task <int> Create(GarmentCorrectionNote garmentCorrectionNote) { int Created = 0; using (var transaction = this.dbContext.Database.BeginTransaction()) { try { EntityExtension.FlagForCreate(garmentCorrectionNote, identityService.Username, USER_AGENT); var supplier = GetSupplier(garmentCorrectionNote.SupplierId); garmentCorrectionNote.CorrectionNo = GenerateNo("NK", garmentCorrectionNote, supplier.Import ? "I" : "L"); if (garmentCorrectionNote.UseVat) { garmentCorrectionNote.NKPN = GenerateNKPN("NKPN", garmentCorrectionNote); } if (garmentCorrectionNote.UseIncomeTax) { garmentCorrectionNote.NKPH = GenerateNKPH("NKPH", garmentCorrectionNote); } if (((garmentCorrectionNote.CorrectionType ?? "").ToUpper() == "HARGA SATUAN")) { garmentCorrectionNote.TotalCorrection = garmentCorrectionNote.Items.Sum(i => (i.PricePerDealUnitAfter - i.PricePerDealUnitBefore) * i.Quantity); } else if ((garmentCorrectionNote.CorrectionType ?? "").ToUpper() == "HARGA TOTAL") { garmentCorrectionNote.TotalCorrection = garmentCorrectionNote.Items.Sum(i => i.PriceTotalAfter - i.PriceTotalBefore); } var garmentDeliveryOrder = dbContext.GarmentDeliveryOrders.First(d => d.Id == garmentCorrectionNote.DOId); garmentDeliveryOrder.IsCorrection = true; EntityExtension.FlagForUpdate(garmentDeliveryOrder, identityService.Username, USER_AGENT); foreach (var item in garmentCorrectionNote.Items) { EntityExtension.FlagForCreate(item, identityService.Username, USER_AGENT); var garmentDeliveryOrderDetail = dbContext.GarmentDeliveryOrderDetails.First(d => d.Id == item.DODetailId); if ((garmentCorrectionNote.CorrectionType ?? "").ToUpper() == "HARGA SATUAN") { garmentDeliveryOrderDetail.PricePerDealUnitCorrection = (double)item.PricePerDealUnitAfter; garmentDeliveryOrderDetail.PriceTotalCorrection = (double)item.PriceTotalAfter; } else if ((garmentCorrectionNote.CorrectionType ?? "").ToUpper() == "HARGA TOTAL") { garmentDeliveryOrderDetail.PriceTotalCorrection = (double)item.PriceTotalAfter; } EntityExtension.FlagForUpdate(garmentDeliveryOrderDetail, identityService.Username, USER_AGENT); } dbSet.Add(garmentCorrectionNote); Created = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }
public static MemoryStream Generate(GarmentCorrectionNote model, IServiceProvider serviceProvider, int clientTimeZoneOffset = 7, string userName = "") { IGarmentDeliveryOrderFacade garmentDeliveryOrderFacade = (IGarmentDeliveryOrderFacade)serviceProvider.GetService(typeof(IGarmentDeliveryOrderFacade)); IGarmentInternalPurchaseOrderFacade garmentInternalPurchaseOrderFacade = (IGarmentInternalPurchaseOrderFacade)serviceProvider.GetService(typeof(IGarmentInternalPurchaseOrderFacade)); 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 garmentDeliveryOrder = garmentDeliveryOrderFacade.ReadById((int)model.DOId); #region Header string addressString = "PT. DAN LIRIS\n" + "Head Offce :\n" + "Kelurahan Banaran, Kecamatan Grogol\n" + "Sukoharjo 57193 - 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", 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("Kode Supplier", normal_font); tableIdentityLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {model.SupplierCode}", normal_font); tableIdentityLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Nama Supplier", normal_font); tableIdentityLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {model.SupplierName}", normal_font); tableIdentityLeft.AddCell(cellLeftNoBorder); PdfPTable tableIdentityRight = new PdfPTable(2); tableIdentityRight.SetWidths(new float[] { 3f, 5f }); cellLeftNoBorder.Phrase = new Phrase("Tanggal", normal_font); tableIdentityRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {model.CorrectionDate.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", normal_font); tableIdentityRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No. Surat Jalan", normal_font); tableIdentityRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {model.DONo}", normal_font); tableIdentityRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Tanggal Surat Jalan", normal_font); tableIdentityRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {garmentDeliveryOrder.DODate.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", 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 = 15f; document.Add(tableIdentity); #endregion #region TableContent PdfPTable tableContent = new PdfPTable(10); tableContent.SetWidths(new float[] { 1.1f, 1.2f, 1f, 1f, 0.9f, 0.7f, 1.2f, 0.8f, 1.2f, 1.3f }); foreach (var columnName in new List <string> { "Plan PO", "Artikel", "Kode Barang", "Nama Barang", "Jumlah SJ", "Satuan", "Harga Satuan", "Jumlah Koreksi", "Harga/Satuan (Koreksi)", "Total Harga" }) { cellCenter.Phrase = new Phrase(columnName, bold_font); tableContent.AddCell(cellCenter); } Dictionary <string, decimal> dictionaryUnitAmount = new Dictionary <string, decimal>(); var totalAmount = 0m; foreach (var item in model.Items) { var garmentInternalPurchaseOrder = garmentInternalPurchaseOrderFacade.ReadById((int)item.POId); var deliveryOrderItem = garmentDeliveryOrder.Items.First(i => i.Details.Any(d => d.Id == item.DODetailId)); var doDetail = deliveryOrderItem.Details.FirstOrDefault(d => d.Id == item.DODetailId); cellLeft.Phrase = new Phrase(item.POSerialNumber, normal_font); tableContent.AddCell(cellLeft); cellLeft.Phrase = new Phrase(garmentInternalPurchaseOrder.Article, normal_font); tableContent.AddCell(cellLeft); cellLeft.Phrase = new Phrase(item.ProductCode, normal_font); tableContent.AddCell(cellLeft); cellLeft.Phrase = new Phrase(item.ProductName, normal_font); tableContent.AddCell(cellLeft); cellRight.Phrase = new Phrase(doDetail.DOQuantity.ToString("n", new CultureInfo("id-ID")), normal_font); tableContent.AddCell(cellRight); cellLeft.Phrase = new Phrase(item.UomIUnit, normal_font); tableContent.AddCell(cellLeft); cellRight.Phrase = new Phrase(doDetail.PricePerDealUnit.ToString("n", new CultureInfo("id-ID")), normal_font); tableContent.AddCell(cellRight); cellRight.Phrase = new Phrase(((double)item.Quantity).ToString(), normal_font); tableContent.AddCell(cellRight); cellRight.Phrase = new Phrase(item.PricePerDealUnitAfter.ToString("n", new CultureInfo("id-ID")), normal_font); tableContent.AddCell(cellRight); var totalHarga = (item.Quantity * item.PricePerDealUnitAfter); totalAmount += totalHarga; if (dictionaryUnitAmount.ContainsKey(garmentInternalPurchaseOrder.UnitCode)) { dictionaryUnitAmount[garmentInternalPurchaseOrder.UnitCode] += totalHarga; } else { dictionaryUnitAmount.Add(garmentInternalPurchaseOrder.UnitCode, totalHarga); } cellRight.Phrase = new Phrase(totalHarga.ToString("n", new CultureInfo("id-ID")), normal_font); tableContent.AddCell(cellRight); } PdfPCell cellContent = new PdfPCell(tableContent); tableContent.ExtendLastRow = false; tableContent.SpacingAfter = 10f; document.Add(tableContent); #endregion #region Footer PdfPTable tableFooter = new PdfPTable(2); tableFooter.SetWidths(new float[] { 1f, 1f }); PdfPTable tableFooterLeft = new PdfPTable(2); tableFooterLeft.SetWidths(new float[] { 3f, 5f }); foreach (var unitAmount in dictionaryUnitAmount) { cellLeftNoBorder.Phrase = new Phrase($"Total {unitAmount.Key}", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {unitAmount.Value.ToString("n", new CultureInfo("id-ID"))}", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); } PdfPTable tableFooterRight = new PdfPTable(2); tableFooterRight.SetWidths(new float[] { 3f, 5f }); cellLeftNoBorder.Phrase = new Phrase("Total Amount", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {totalAmount.ToString("n", new CultureInfo("id-ID"))}", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Mata Uang", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {model.CurrencyCode}", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Total Harga Pokok (Rp)", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {(totalAmount * (decimal)garmentDeliveryOrder.DOCurrencyRate).ToString("n", new CultureInfo("id-ID"))}", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); PdfPCell cellFooterLeft = new PdfPCell(tableFooterLeft) { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; tableFooter.AddCell(cellFooterLeft); PdfPCell cellFooterRight = new PdfPCell(tableFooterRight) { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; tableFooter.AddCell(cellFooterRight); PdfPCell cellFooter = new PdfPCell(tableFooter); tableFooter.ExtendLastRow = false; tableFooter.SpacingAfter = 15f; document.Add(tableFooter); #endregion #region TableSignature var signer = new List <string> { "Administrasi", "Staff Pembelian", "Verifikasi" }; 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.SpacingBefore = 20f; 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 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 async Task <int> Create(GarmentCorrectionNote garmentCorrectionNote, bool isImport, string user, int clientTimeZoneOffset = 7) { int Created = 0; using (var transaction = this.dbContext.Database.BeginTransaction()) { try { EntityExtension.FlagForCreate(garmentCorrectionNote, user, USER_AGENT); var supplier = GetSupplier(garmentCorrectionNote.SupplierId); var supplierImport = false; if (supplier != null) { supplierImport = supplier.Import; } garmentCorrectionNote.CorrectionNo = await GenerateNo(garmentCorrectionNote, supplierImport, clientTimeZoneOffset); garmentCorrectionNote.TotalCorrection = (garmentCorrectionNote.Items.Sum(i => i.PriceTotalAfter)) * (-1); if (garmentCorrectionNote.UseIncomeTax == true) { garmentCorrectionNote.NKPH = await GenerateNKPH(garmentCorrectionNote, clientTimeZoneOffset); } else { garmentCorrectionNote.NKPH = ""; } if (garmentCorrectionNote.UseVat == true) { garmentCorrectionNote.NKPN = await GenerateNKPN(garmentCorrectionNote, clientTimeZoneOffset); } else { garmentCorrectionNote.NKPN = ""; } var garmentDeliveryOrder = dbContext.GarmentDeliveryOrders.First(d => d.Id == garmentCorrectionNote.DOId); garmentDeliveryOrder.IsCorrection = true; EntityExtension.FlagForUpdate(garmentDeliveryOrder, user, USER_AGENT); foreach (var item in garmentCorrectionNote.Items) { item.Quantity = item.Quantity * (-1); item.PriceTotalAfter = item.Quantity * item.PricePerDealUnitAfter; EntityExtension.FlagForCreate(item, user, USER_AGENT); var garmentDeliveryOrderDetail = dbContext.GarmentDeliveryOrderDetails.First(d => d.Id == item.DODetailId); var epoDetail = dbContext.GarmentExternalPurchaseOrderItems.First(d => d.Id == garmentDeliveryOrderDetail.EPOItemId); //garmentDeliveryOrderDetail.QuantityCorrection = ((double)item.Quantity * (-1)) + garmentDeliveryOrderDetail.QuantityCorrection; //garmentDeliveryOrderDetail.PriceTotalCorrection = garmentDeliveryOrderDetail.QuantityCorrection * garmentDeliveryOrderDetail.PricePerDealUnitCorrection; garmentDeliveryOrderDetail.ReturQuantity = garmentDeliveryOrderDetail.ReturQuantity + ((double)item.Quantity * (-1)); epoDetail.DOQuantity = epoDetail.DOQuantity + (double)item.Quantity; EntityExtension.FlagForUpdate(garmentDeliveryOrderDetail, user, USER_AGENT); } dbSet.Add(garmentCorrectionNote); Created = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }
public async Task <List <GarmentCorrectionNote> > GetNewDoubleCorrectionData(string user) { var garmentDeliveryOrder = await Task.Run(() => garmentDeliveryOrderDataUtil.GetTestData()); GarmentCorrectionNote garmentCorrectionNote = new GarmentCorrectionNote { CorrectionNo = "NK1234L", CorrectionType = "Jumlah", CorrectionDate = DateTimeOffset.Now, DOId = garmentDeliveryOrder.Id, DONo = garmentDeliveryOrder.DONo, SupplierId = garmentDeliveryOrder.SupplierId, SupplierCode = garmentDeliveryOrder.SupplierCode, SupplierName = garmentDeliveryOrder.SupplierName, Remark = "Remark", NKPH = "NKPH1234L", NKPN = "NKPN1234L", Items = new List <GarmentCorrectionNoteItem>() }; foreach (var item in garmentDeliveryOrder.Items) { foreach (var detail in item.Details) { garmentCorrectionNote.Items.Add( new GarmentCorrectionNoteItem { DODetailId = detail.Id, EPOId = item.EPOId, EPONo = item.EPONo, PRId = detail.PRId, PRNo = detail.PRNo, POId = detail.POId, POSerialNumber = detail.POSerialNumber, RONo = detail.RONo, ProductId = detail.ProductId, ProductCode = detail.ProductCode, ProductName = detail.ProductName, Quantity = (decimal)detail.QuantityCorrection, UomId = Convert.ToInt32(detail.UomId), UomIUnit = detail.UomUnit, }); } } GarmentCorrectionNote garmentCorrectionNotes = new GarmentCorrectionNote { CorrectionNo = "NK1234L", CorrectionType = "HARGa total", CorrectionDate = DateTimeOffset.Now, DOId = garmentDeliveryOrder.Id, DONo = garmentDeliveryOrder.DONo, SupplierId = garmentDeliveryOrder.SupplierId, SupplierCode = garmentDeliveryOrder.SupplierCode, SupplierName = garmentDeliveryOrder.SupplierName, Remark = "Remark", NKPH = "NKPH1234L", NKPN = "NKPN1234L", Items = new List <GarmentCorrectionNoteItem>() }; foreach (var item in garmentDeliveryOrder.Items) { foreach (var detail in item.Details) { garmentCorrectionNotes.Items.Add( new GarmentCorrectionNoteItem { DODetailId = detail.Id, EPOId = item.EPOId, EPONo = item.EPONo, PRId = detail.PRId, PRNo = detail.PRNo, POId = detail.POId, POSerialNumber = detail.POSerialNumber, RONo = detail.RONo, ProductId = detail.ProductId, ProductCode = detail.ProductCode, ProductName = detail.ProductName, Quantity = (decimal)detail.QuantityCorrection, UomId = Convert.ToInt32(detail.UomId), UomIUnit = detail.UomUnit, }); } } var data1 = await garmentCorrectionNoteQuantityFacade.Create(garmentCorrectionNote, false, user, 7); var data2 = await garmentCorrectionNoteQuantityFacade.Create(garmentCorrectionNotes, false, user, 7); List <GarmentCorrectionNote> lisdata = new List <GarmentCorrectionNote>(); lisdata.Add(garmentCorrectionNote); lisdata.Add(garmentCorrectionNotes); return(lisdata); //return garmentCorrectionNote; }