public PurchasingMemoDetailTextileDto Read(int id) { var model = _dbContext.PurchasingMemoDetailTextiles.FirstOrDefault(entity => entity.Id == id); if (model != null) { var memoIsCreated = _dbContext.PurchasingMemoTextiles.Any(entity => entity.MemoDetailId == model.Id); var result = new PurchasingMemoDetailTextileDto(model.Date, new DivisionDto(model.DivisionId, model.DivisionCode, model.DivisionName), new CurrencyDto(model.CurrencyId, model.CurrencyCode, model.CurrencyRate), model.SupplierIsImport, model.Type, new List <FormItemDto>(), new List <FormDetailDto>(), model.Remark, model.Id, model.DocumentNo, memoIsCreated); if (model.Type == PurchasingMemoType.Disposition) { var items = _dbContext.PurchasingMemoDetailTextileItems.Where(entity => entity.PurchasingMemoDetailTextileId == model.Id).ToList(); var itemIds = items.Select(item => item.Id).ToList(); var details = _dbContext.PurchasingMemoDetailTextileDetails.Where(entity => entity.PurchasingMemoDetailTextileId == model.Id && itemIds.Contains(entity.PurchasingMemoDetailTextileItemId)).ToList(); var detailIds = details.Select(detail => detail.Id).ToList(); var unitReceiptNotes = _dbContext.PurchasingMemoDetailTextileUnitReceiptNotes.Where(entity => entity.PurchasingMemoDetailTextileId == model.Id && itemIds.Contains(entity.PurchasingMemoDetailTextileItemId) && detailIds.Contains(entity.PurchasingMemoDetailTextileDetailId)).ToList(); foreach (var item in items) { var itemDetails = details.Where(detail => detail.PurchasingMemoDetailTextileItemId == item.Id).ToList(); var disposition = new DispositionDto(item.DispositionId, item.DispositionNo, item.DispositionDate, new List <FormDetailDto>()); foreach (var itemDetail in itemDetails) { var detailUnitReceiptNotes = unitReceiptNotes.Where(unitReceiptNote => unitReceiptNote.PurchasingMemoDetailTextileDetailId == itemDetail.Id).Select(unitReceiptNote => new UnitReceiptNoteDto(unitReceiptNote.UnitReceiptNoteId, unitReceiptNote.UnitReceiptNoteNo, unitReceiptNote.UnitReceiptNoteDate)).ToList(); var expenditure = new ExpenditureDto(itemDetail.ExpenditureId, itemDetail.ExpenditureNo, itemDetail.ExpenditureDate); var supplier = new SupplierDto(itemDetail.SupplierId, itemDetail.SupplierCode, itemDetail.SupplierName); var unitPaymentOrder = new UnitPaymentOrderDto(itemDetail.UnitPaymentOrderId, itemDetail.UnitPaymentOrderNo, itemDetail.UnitPaymentOrderDate); disposition.Details.Add(new FormDetailDto(expenditure, supplier, itemDetail.Remark, unitPaymentOrder, detailUnitReceiptNotes, itemDetail.PurchaseAmountCurrency, itemDetail.PurchaseAmount, itemDetail.PaymentAmountCurrency, itemDetail.PaymentAmount)); } result.Items.Add(new FormItemDto(disposition)); } } else { var details = _dbContext.PurchasingMemoDetailTextileDetails.Where(entity => entity.PurchasingMemoDetailTextileId == model.Id).ToList(); var detailIds = details.Select(detail => detail.Id).ToList(); var unitReceiptNotes = _dbContext.PurchasingMemoDetailTextileUnitReceiptNotes.Where(entity => entity.PurchasingMemoDetailTextileId == model.Id && detailIds.Contains(entity.PurchasingMemoDetailTextileDetailId)).ToList(); foreach (var itemDetail in details) { var detailUnitReceiptNotes = unitReceiptNotes.Where(unitReceiptNote => unitReceiptNote.PurchasingMemoDetailTextileDetailId == itemDetail.Id).Select(unitReceiptNote => new UnitReceiptNoteDto(unitReceiptNote.UnitReceiptNoteId, unitReceiptNote.UnitReceiptNoteNo, unitReceiptNote.UnitReceiptNoteDate)).ToList(); var expenditure = new ExpenditureDto(itemDetail.ExpenditureId, itemDetail.ExpenditureNo, itemDetail.ExpenditureDate); var supplier = new SupplierDto(itemDetail.SupplierId, itemDetail.SupplierCode, itemDetail.SupplierName); var unitPaymentOrder = new UnitPaymentOrderDto(itemDetail.UnitPaymentOrderId, itemDetail.UnitPaymentOrderNo, itemDetail.UnitPaymentOrderDate); result.Details.Add(new FormDetailDto(expenditure, supplier, itemDetail.Remark, unitPaymentOrder, detailUnitReceiptNotes, itemDetail.PurchaseAmountCurrency, itemDetail.PurchaseAmount, itemDetail.PaymentAmountCurrency, itemDetail.PaymentAmount)); } } return(result); } else { return(null); } }
private static void SetHeader(Document document, PurchasingMemoDetailTextileDto purchasingMemoDetailTextile) { var table = new PdfPTable(2) { WidthPercentage = 100 }; var cell = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE }; var rightCell = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE }; var leftCell = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE }; cell.Phrase = new Phrase("PT. DANLIRIS", _headerFont); table.AddCell(cell); rightCell.Phrase = new Phrase($"No. {purchasingMemoDetailTextile.DocumentNo}", _biggerFont); table.AddCell(rightCell); leftCell.Colspan = 2; leftCell.Phrase = new Phrase("Kel. Banaran (Sel. Laweyan) Telp. 714400", _smallFont); table.AddCell(leftCell); leftCell.Phrase = new Phrase("PO. Box. 166 Solo-57100 Indonesia", _smallFont); table.AddCell(leftCell); var importLocal = purchasingMemoDetailTextile.SupplierIsImport ? "IMPOR" : "LOKAL"; leftCell.Phrase = new Phrase($"PEMBAYARAN HUTANG DAG {importLocal} TEKSTIL RK UANG MUKA PEMBELIAN {importLocal}", _biggerFont); leftCell.PaddingTop = 5; table.AddCell(leftCell); rightCell.Colspan = 2; rightCell.Phrase = new Phrase($"TEX(151100)", _smallFont); rightCell.PaddingBottom = 10; table.AddCell(rightCell); document.Add(table); }
public static MemoryStream Generate(PurchasingMemoDetailTextileDto purchasingMemoDetailTextile, string username, int timeoffset) { var document = new Document(PageSize.A4, 25, 25, 25, 25); var stream = new MemoryStream(); PdfWriter.GetInstance(document, stream); document.Open(); SetHeader(document, purchasingMemoDetailTextile); SetTable(document, purchasingMemoDetailTextile); SetFooter(document, purchasingMemoDetailTextile, timeoffset); document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
private static void SetFooter(Document document, PurchasingMemoDetailTextileDto purchasingMemoDetailTextile, int offSet) { PdfPTable table = new PdfPTable(3) { WidthPercentage = 100 }; table.SetWidths(new float[] { 1f, 1f, 1f }); PdfPCell cell = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, }; PdfPCell cellColspan2 = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Colspan = 2 }; cellColspan2.Phrase = new Phrase($"Keterangan : {purchasingMemoDetailTextile.Remark}", _smallFont); cellColspan2.PaddingBottom = 10; table.AddCell(cellColspan2); cell.Phrase = new Phrase(); table.AddCell(cell); //cellColspan2.Phrase = new Phrase("Nomor Memo Pusat :", _smallFont); //table.AddCell(cellColspan2); //cell.Phrase = new Phrase(); //table.AddCell(cell); cell.Phrase = new Phrase(); table.AddCell(cell); cell.Phrase = new Phrase(); table.AddCell(cell); cell.Phrase = new Phrase(); table.AddCell(cell); cell.Phrase = new Phrase("Mengetahui", _smallFont); table.AddCell(cell); cell.Phrase = new Phrase(); table.AddCell(cell); cell.Phrase = new Phrase($"Solo, {DateTime.UtcNow.AddHours(offSet).ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", _smallFont); table.AddCell(cell); cell.Phrase = new Phrase("Kepala Pembukuan", _smallFont); table.AddCell(cell); cell.Phrase = new Phrase(); table.AddCell(cell); cell.Phrase = new Phrase("Yang Membuat", _smallFont); table.AddCell(cell); for (var i = 0; i < 4; i++) { cell.Phrase = new Phrase(); table.AddCell(cell); cell.Phrase = new Phrase(); table.AddCell(cell); cell.Phrase = new Phrase(); table.AddCell(cell); } cell.Phrase = new Phrase("(..................)", _smallFont); table.AddCell(cell); cell.Phrase = new Phrase(); table.AddCell(cell); cell.Phrase = new Phrase($"(..................)", _smallFont); table.AddCell(cell); document.Add(table); }
private static void SetTable(Document document, PurchasingMemoDetailTextileDto purchasingMemoDetailTextile) { var table = new PdfPTable(9) { WidthPercentage = 100 }; table.SetWidths(new float[] { 5f, 12f, 20f, 20f, 15f, 15f, 12f, 15f, 15f }); if (purchasingMemoDetailTextile.Type == PurchasingMemoType.Disposition) { table = new PdfPTable(10) { WidthPercentage = 100 }; table.SetWidths(new float[] { 5f, 12f, 12f, 20f, 20f, 15f, 15f, 12f, 15f, 15f }); } var cell = new PdfPCell() { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE }; var cellColspan3 = new PdfPCell() { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Colspan = 3 }; var cellAlignRight = new PdfPCell() { HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE }; var cellAlignLeft = new PdfPCell() { HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE }; var cellNoBorderAlignRight = new PdfPCell() { HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Border = Rectangle.NO_BORDER }; double totalDebit = 0; double totalCredit = 0; int no = 1; if (purchasingMemoDetailTextile.Type == PurchasingMemoType.Disposition) { SetTableHeaderDisposition(table); var sumPurchaseAmount = purchasingMemoDetailTextile.Items.SelectMany(element => element.Disposition.Details).Sum(element => element.PurchaseAmount); var sumPaymentAmount = purchasingMemoDetailTextile.Items.SelectMany(element => element.Disposition.Details).Sum(element => element.PaymentAmount); var sumPurchaseAmountCurrency = purchasingMemoDetailTextile.Items.SelectMany(element => element.Disposition.Details).Sum(element => element.PurchaseAmountCurrency); var sumPaymentAmountCurrency = purchasingMemoDetailTextile.Items.SelectMany(element => element.Disposition.Details).Sum(element => element.PaymentAmountCurrency); var difference = sumPaymentAmount - sumPurchaseAmount; var differenceCurrency = sumPaymentAmountCurrency - sumPurchaseAmountCurrency; foreach (var item in purchasingMemoDetailTextile.Items) { foreach (var detail in item.Disposition.Details) { cell.Phrase = new Phrase(no.ToString(), _smallerFont); table.AddCell(cell); cell.Phrase = new Phrase(item.Disposition.DocumentNo, _smallFont); table.AddCell(cell); cell.Phrase = new Phrase(detail.Expenditure.DocumentNo, _smallFont); table.AddCell(cell); cellAlignLeft.Phrase = new Phrase(detail.Supplier.Name, _smallFont); table.AddCell(cellAlignLeft); cellAlignLeft.Phrase = new Phrase(detail.Remark, _smallFont); table.AddCell(cellAlignLeft); cellAlignRight.Phrase = new Phrase(detail.PaymentAmountCurrency.ToString("#,##0.#0"), _smallFont); table.AddCell(cellAlignRight); cellAlignRight.Phrase = new Phrase(detail.PaymentAmount.ToString("#,##0.#0"), _smallFont); table.AddCell(cellAlignRight); cell.Phrase = new Phrase(detail.UnitPaymentOrder.UnitPaymentOrderNo, _smallFont); table.AddCell(cell); cellAlignRight.Phrase = new Phrase(detail.PurchaseAmountCurrency.ToString("#,##0.#0"), _smallFont); table.AddCell(cellAlignRight); cellAlignRight.Phrase = new Phrase(detail.PurchaseAmount.ToString("#,##0.#0"), _smallFont); table.AddCell(cellAlignRight); //totalDebit += detail.DebitAmount; //totalCredit += detail.CreditAmount; no++; } } cellNoBorderAlignRight.Colspan = 5; cellNoBorderAlignRight.Phrase = new Phrase("Total Bayar", _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Colspan = 1; cellNoBorderAlignRight.Phrase = new Phrase(sumPaymentAmountCurrency.ToString("#,##0.#0"), _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Phrase = new Phrase(sumPaymentAmount.ToString("#,##0.#0"), _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Phrase = new Phrase("Total Beli", _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Phrase = new Phrase(sumPurchaseAmountCurrency.ToString("#,##0.#0"), _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Phrase = new Phrase(sumPurchaseAmount.ToString("#,##0.#0"), _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Colspan = 8; cellNoBorderAlignRight.Phrase = new Phrase("Selisih", _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Colspan = 1; var differenceCurrencyString = sumPaymentAmountCurrency > sumPurchaseAmountCurrency ? "(" + differenceCurrency.ToString("#,##0.#0") + ")" : differenceCurrency.ToString("#,##0.#0"); var differenceString = sumPaymentAmount > sumPurchaseAmount ? "(" + difference.ToString("#,##0.#0") + ")" : difference.ToString("#,##0.#0"); cellNoBorderAlignRight.Phrase = new Phrase(differenceCurrencyString, _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Phrase = new Phrase(differenceString, _smallFont); table.AddCell(cellNoBorderAlignRight); } else { SetTableHeaderNonDisposition(table); var sumPurchaseAmount = purchasingMemoDetailTextile.Details.Sum(element => element.PurchaseAmount); var sumPaymentAmount = purchasingMemoDetailTextile.Details.Sum(element => element.PaymentAmount); var sumPurchaseAmountCurrency = purchasingMemoDetailTextile.Details.Sum(element => element.PurchaseAmountCurrency); var sumPaymentAmountCurrency = purchasingMemoDetailTextile.Details.Sum(element => element.PaymentAmountCurrency); var difference = sumPaymentAmount - sumPurchaseAmount; var differenceCurrency = sumPaymentAmountCurrency - sumPurchaseAmountCurrency; foreach (var detail in purchasingMemoDetailTextile.Details) { cell.Phrase = new Phrase(no.ToString(), _smallerFont); table.AddCell(cell); cell.Phrase = new Phrase(detail.Expenditure.DocumentNo, _smallFont); table.AddCell(cell); cellAlignLeft.Phrase = new Phrase(detail.Supplier.Name, _smallFont); table.AddCell(cellAlignLeft); cellAlignLeft.Phrase = new Phrase(detail.Remark, _smallFont); table.AddCell(cellAlignLeft); cellAlignRight.Phrase = new Phrase(detail.PaymentAmountCurrency.ToString("#,##0.#0"), _smallFont); table.AddCell(cellAlignRight); cellAlignRight.Phrase = new Phrase(detail.PaymentAmount.ToString("#,##0.#0"), _smallFont); table.AddCell(cellAlignRight); cell.Phrase = new Phrase(detail.UnitPaymentOrder.UnitPaymentOrderNo, _smallFont); table.AddCell(cell); cellAlignRight.Phrase = new Phrase(detail.PurchaseAmountCurrency.ToString("#,##0.#0"), _smallFont); table.AddCell(cellAlignRight); cellAlignRight.Phrase = new Phrase(detail.PurchaseAmount.ToString("#,##0.#0"), _smallFont); table.AddCell(cellAlignRight); //totalDebit += detail.DebitAmount; //totalCredit += detail.CreditAmount; no++; } cellNoBorderAlignRight.Colspan = 4; cellNoBorderAlignRight.Phrase = new Phrase("Total Bayar", _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Colspan = 1; cellNoBorderAlignRight.Phrase = new Phrase(sumPaymentAmountCurrency.ToString("#,##0.#0"), _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Phrase = new Phrase(sumPaymentAmount.ToString("#,##0.#0"), _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Phrase = new Phrase("Total Beli", _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Phrase = new Phrase(sumPurchaseAmountCurrency.ToString("#,##0.#0"), _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Phrase = new Phrase(sumPurchaseAmount.ToString("#,##0.#0"), _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Colspan = 7; cellNoBorderAlignRight.Phrase = new Phrase("Selisih", _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Colspan = 1; var differenceCurrencyString = sumPaymentAmountCurrency > sumPurchaseAmountCurrency ? "(" + differenceCurrency.ToString("#,##0.#0") + ")" : differenceCurrency.ToString("#,##0.#0"); var differenceString = sumPaymentAmount > sumPurchaseAmount ? "(" + difference.ToString("#,##0.#0") + ")" : difference.ToString("#,##0.#0"); cellNoBorderAlignRight.Phrase = new Phrase(differenceCurrencyString, _smallFont); table.AddCell(cellNoBorderAlignRight); cellNoBorderAlignRight.Phrase = new Phrase(differenceString, _smallFont); table.AddCell(cellNoBorderAlignRight); } //cellColspan3.Phrase = new Phrase("Jumlah Total", _smallBoldFont); //table.AddCell(cellColspan3); //cellAlignRight.Phrase = new Phrase(totalDebit.ToString("#,##0.#0"), _smallBoldFont); //table.AddCell(cellAlignRight); //cellAlignRight.Phrase = new Phrase(totalCredit.ToString("#,##0.#0"), _smallBoldFont); //table.AddCell(cellAlignRight); document.Add(table); }