public async Task GetPdf_WithoutException_ReturnOk()
        {
            var serviceProviderMock = new Mock <IServiceProvider>();

            var model = new MemoGarmentPurchasingModel();

            model.MemoGarmentPurchasingDetails = new List <MemoGarmentPurchasingDetailModel>();
            var serviceMock = new Mock <IMemoGarmentPurchasingService>();

            serviceMock
            .Setup(service => service.ReadByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(model);

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(IMemoGarmentPurchasingService))).Returns(serviceMock.Object);

            var identityServiceMock = new Mock <IIdentityService>();

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(IIdentityService))).Returns(identityServiceMock.Object);

            var controller = GetController(serviceProviderMock.Object);

            var response = await controller.GetPdf(It.IsAny <int>());

            Assert.NotNull(response);
        }
        public async Task GetXls_WithoutException_ReturnOk()
        {
            var serviceProviderMock = new Mock <IServiceProvider>();

            var model = new MemoGarmentPurchasingModel();

            model.MemoGarmentPurchasingDetails = new List <MemoGarmentPurchasingDetailModel>();
            var serviceMock = new Mock <IMemoGarmentPurchasingReportService>();

            serviceMock
            .Setup(service => service.GenerateExcel(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <bool>()))
            .Returns(new MemoryStream());

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(IMemoGarmentPurchasingReportService))).Returns(serviceMock.Object);

            var identityServiceMock = new Mock <IIdentityService>();

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(IIdentityService))).Returns(identityServiceMock.Object);

            var controller = GetController(serviceProviderMock.Object);

            var response = await controller.GetXls(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <bool>());

            Assert.NotNull(response);
        }
        public async Task <int> CreateAsync(MemoGarmentPurchasingModel model)
        {
            var transaction = _context.Database.BeginTransaction();

            try
            {
                model.MemoNo      = GetMemoNo(model);
                model.TotalAmount = GetTotalAmount(model.MemoGarmentPurchasingDetails);

                EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent);

                foreach (var detail in model.MemoGarmentPurchasingDetails)
                {
                    EntityExtension.FlagForCreate(detail, _identityService.Username, UserAgent);
                }

                _context.Add(model);
                var result = await _context.SaveChangesAsync();

                transaction.Commit();
                return(result);
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
        }
示例#4
0
        public async Task <IActionResult> GetPdf([FromRoute] int Id)
        {
            try
            {
                var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf");
                int timeOffset     = Convert.ToInt32(Request.Headers["x-timezone-offset"]);

                MemoGarmentPurchasingModel model = await _service.ReadByIdAsync(Id);

                if (model == null)
                {
                    Dictionary <string, object> Result =
                        new ResultFormatter(ApiVersion, General.NOT_FOUND_STATUS_CODE, General.NOT_FOUND_MESSAGE)
                        .Fail();
                    return(NotFound(Result));
                }

                MemoryStream stream = MemoGarmentPurchasingPdfTemplate.GeneratePdfTemplate(model, timeOffset);
                return(new FileStreamResult(stream, "application/pdf")
                {
                    FileDownloadName = $"Bukti Memorial - {model.MemoNo}.pdf"
                });
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }
        private string GetMemoNo(MemoGarmentPurchasingModel model)
        {
            var date  = DateTime.Now;
            var count = 1 + _context.MemoGarmentPurchasings.Count(x => x.CreatedUtc.Year.Equals(date.Year) && x.CreatedUtc.Month.Equals(date.Month));

            var generatedNo = $"{date.ToString("MM")}{date.ToString("yy")}.MG.{count.ToString("0000")}";

            return(generatedNo);
        }
        public async Task <int> UpdateAsync(int id, MemoGarmentPurchasingModel model)
        {
            var transaction = _context.Database.BeginTransaction();

            try
            {
                var modelToUpdate = await ReadByIdAsync(id);

                modelToUpdate.Remarks = model.Remarks;
                EntityExtension.FlagForUpdate(modelToUpdate, _identityService.Username, UserAgent);
                _context.Update(modelToUpdate);

                var modelIds       = model.MemoGarmentPurchasingDetails.Select(x => x.Id).ToList();
                var detailToUpdate = modelToUpdate.MemoGarmentPurchasingDetails.Select(x =>
                {
                    var dat = model.MemoGarmentPurchasingDetails.Where(y => y.Id.Equals(x.Id)).FirstOrDefault();
                    if (dat != null)
                    {
                        x.COAId         = dat.COAId;
                        x.COAName       = dat.COAName;
                        x.COANo         = dat.COANo;
                        x.DebitNominal  = dat.DebitNominal;
                        x.CreditNominal = dat.CreditNominal;
                        EntityExtension.FlagForUpdate(x, _identityService.Username, UserAgent);
                        return(x);
                    }

                    EntityExtension.FlagForDelete(x, _identityService.Username, UserAgent);
                    return(x);
                });
                _context.MemoGarmentPurchasingDetails.UpdateRange(detailToUpdate);

                if (model.MemoGarmentPurchasingDetails.Any(x => x.Id < 1))
                {
                    var detailToCreate = model.MemoGarmentPurchasingDetails.Where(x => x.Id < 1).Select(x =>
                    {
                        x.MemoId = modelToUpdate.Id;
                        EntityExtension.FlagForCreate(x, _identityService.Username, UserAgent);
                        return(x);
                    });
                    _context.MemoGarmentPurchasingDetails.AddRange(detailToCreate);
                }

                var result = await _context.SaveChangesAsync();

                transaction.Commit();
                return(result);
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
        }
示例#7
0
        private static void SetHeader(Document document, MemoGarmentPurchasingModel data)
        {
            var table = new PdfPTable(1)
            {
                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 centeredCell = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_CENTER,
                VerticalAlignment   = Element.ALIGN_MIDDLE
            };

            cell.Phrase = new Phrase("PT. DANLIRIS", _headerFont);
            table.AddCell(cell);

            cell.Phrase = new Phrase("Kel. Banaran (Sel. Laweyan) Telp. 714400", _smallFont);
            table.AddCell(cell);

            cell.Phrase = new Phrase("PO. Box. 166 Solo-57100 Indonesia", _smallFont);
            table.AddCell(cell);

            centeredCell.Phrase     = new Phrase("BUKTI MEMORIAL", _biggerFont);
            centeredCell.PaddingTop = 5;
            table.AddCell(centeredCell);

            rightCell.Phrase        = new Phrase($"No. Memo: {data.MemoNo}", _smallFont);
            rightCell.PaddingBottom = 10;
            table.AddCell(rightCell);

            document.Add(table);
        }
示例#8
0
        public static MemoryStream GeneratePdfTemplate(MemoGarmentPurchasingModel data, int offSet)
        {
            var document = new Document(PageSize.A4, 25, 25, 25, 25);
            var stream   = new MemoryStream();

            PdfWriter.GetInstance(document, stream);
            document.Open();

            SetHeader(document, data);

            SetReportTable(document, data);

            SetFooter(document, data, offSet);

            document.Close();
            byte[] byteInfo = stream.ToArray();
            stream.Write(byteInfo, 0, byteInfo.Length);
            stream.Position = 0;

            return(stream);
        }
        private static void SetFooter(Document document, MemoGarmentPurchasingModel data, 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 : {data.Remarks}", _smallFont);
            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($"( {data.CreatedBy} )", _smallFont);
            table.AddCell(cell);

            document.Add(table);
        }
        private static void SetReportTable(Document document, MemoGarmentPurchasingModel data)
        {
            var table = new PdfPTable(8)
            {
                WidthPercentage = 100
            };

            table.SetWidths(new float[] { 5f, 10f, 10f, 10f, 20f, 10f, 10f, 10f });

            SetReportTableHeader(table);

            var cell = new PdfPCell()
            {
                HorizontalAlignment = Element.ALIGN_CENTER,
                VerticalAlignment   = Element.ALIGN_MIDDLE
            };

            var cellColspan5 = new PdfPCell()
            {
                HorizontalAlignment = Element.ALIGN_CENTER,
                VerticalAlignment   = Element.ALIGN_MIDDLE,
                Colspan             = 5
            };

            var cellAlignRight = new PdfPCell()
            {
                HorizontalAlignment = Element.ALIGN_RIGHT,
                VerticalAlignment   = Element.ALIGN_MIDDLE
            };

            var cellAlignLeft = new PdfPCell()
            {
                HorizontalAlignment = Element.ALIGN_LEFT,
                VerticalAlignment   = Element.ALIGN_MIDDLE
            };

            double totalDebit  = 0;
            double totalCredit = 0;
            int    index       = 1;

            cell.Phrase = new Phrase(index.ToString(), _smallerFont);
            table.AddCell(cell);

            cell.Phrase = new Phrase(index.Equals(1) ? data.MemoNo : "", _smallerFont);
            table.AddCell(cell);

            cell.Phrase = new Phrase(index.Equals(1) ? data.MemoDate.ToString("dd/MM/yy") : "", _smallerFont);
            table.AddCell(cell);

            bool isFirstDetail = false;

            foreach (var detail in data.MemoGarmentPurchasingDetails)
            {
                if (isFirstDetail)
                {
                    cell.Phrase = new Phrase(index.ToString(), _smallerFont);
                    table.AddCell(cell);
                    cell.Phrase = new Phrase();
                    table.AddCell(cell);
                    cell.Phrase = new Phrase();
                    table.AddCell(cell);
                }

                cell.Phrase = new Phrase(detail.COANo, _smallerFont);
                table.AddCell(cell);

                cellAlignLeft.Phrase = new Phrase(detail.COAName, _smallerFont);
                table.AddCell(cellAlignLeft);

                cellAlignLeft.Phrase = new Phrase(detail.MemoGarmentPurchasing.Remarks, _smallerFont);
                table.AddCell(cellAlignLeft);

                cellAlignRight.Phrase = new Phrase(detail.DebitNominal.ToString("#,##0.#0"), _smallerFont);
                table.AddCell(cellAlignRight);

                cellAlignRight.Phrase = new Phrase(detail.CreditNominal.ToString("#,##0.#0"), _smallerFont);
                table.AddCell(cellAlignRight);

                totalDebit   += detail.DebitNominal;
                totalCredit  += detail.CreditNominal;
                isFirstDetail = true;
                index++;
            }

            cellColspan5.Phrase = new Phrase("Jumlah ", _smallerBoldFont);
            table.AddCell(cellColspan5);

            cellAlignRight.Phrase = new Phrase(totalDebit.ToString("#,##0.#0"), _smallerBoldFont);
            table.AddCell(cellAlignRight);

            cellAlignRight.Phrase = new Phrase(totalCredit.ToString("#,##0.#0"), _smallerBoldFont);
            table.AddCell(cellAlignRight);

            cell.Phrase = new Phrase();
            table.AddCell(cell);

            document.Add(table);
        }
示例#11
0
        private static void SetReportTable(Document document, MemoGarmentPurchasingModel data)
        {
            var table = new PdfPTable(5)
            {
                WidthPercentage = 100
            };

            table.SetWidths(new float[] { 5f, 12f, 23f, 15f, 15f });

            SetReportTableHeader(table);

            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
            };

            int totalDebit  = 0;
            int totalCredit = 0;
            int no          = 1;

            foreach (var detail in data.MemoGarmentPurchasingDetails)
            {
                cell.Phrase = new Phrase(no + "", _smallerFont);
                table.AddCell(cell);

                cell.Phrase = new Phrase(detail.COANo, _smallFont);
                table.AddCell(cell);

                cellAlignLeft.Phrase = new Phrase(detail.COAName, _smallFont);
                table.AddCell(cellAlignLeft);

                cellAlignRight.Phrase = new Phrase(detail.DebitNominal.ToString("#,##0.#0"), _smallFont);
                table.AddCell(cellAlignRight);

                cellAlignRight.Phrase = new Phrase(detail.CreditNominal.ToString("#,##0.#0"), _smallFont);
                table.AddCell(cellAlignRight);

                totalDebit  += detail.DebitNominal;
                totalCredit += detail.CreditNominal;
                no++;
            }

            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);
        }