public async Task <IActionResult> Post([FromBody] GarmentShippingLocalSalesNoteViewModel viewModel)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(viewModel);
                var result = await _service.Create(viewModel);

                return(Created("/", result));
            }
            catch (ServiceValidationException ex)
            {
                var Result = new
                {
                    error      = ResultFormatter.Fail(ex),
                    apiVersion = "1.0.0",
                    statusCode = HttpStatusCode.BadRequest,
                    message    = "Data does not pass validation"
                };

                return(new BadRequestObjectResult(Result));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
コード例 #2
0
        public void Validate_DefaultValue()
        {
            GarmentShippingLocalSalesNoteViewModel viewModel = new GarmentShippingLocalSalesNoteViewModel();

            var result = viewModel.Validate(null);

            Assert.NotEmpty(result.ToList());
        }
        public async Task <IActionResult> PutRejectFinance([FromRoute] int id, [FromBody] GarmentShippingLocalSalesNoteViewModel viewModel)
        {
            try
            {
                VerifyUser();
                var result = await _service.RejectedFinance(id, viewModel);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
コード例 #4
0
        public void Validate_EmptyValue()
        {
            GarmentShippingLocalSalesNoteViewModel viewModel = new GarmentShippingLocalSalesNoteViewModel
            {
                date            = DateTimeOffset.MinValue,
                transactionType = new TransactionType {
                    id = 0
                },
                buyer = new Buyer {
                    Id = 0
                },
                tempo       = 0,
                paymentType = "TEMPO"
            };

            var result = viewModel.Validate(null);

            Assert.NotEmpty(result.ToList());
        }
コード例 #5
0
        public void Validate_ItemsEmptyValue()
        {
            GarmentShippingLocalSalesNoteViewModel viewModel = new GarmentShippingLocalSalesNoteViewModel();

            viewModel.items = new List <GarmentShippingLocalSalesNoteItemViewModel>
            {
                new GarmentShippingLocalSalesNoteItemViewModel
                {
                    product = new ProductViewModel {
                        id = 0
                    },
                    uom = new UnitOfMeasurement {
                        Id = 0
                    }
                }
            };

            var result = viewModel.Validate(null);

            Assert.NotEmpty(result.ToList());
        }
コード例 #6
0
        public async Task <IActionResult> GetPDF([FromRoute] int Id)
        {
            if (!ModelState.IsValid)
            {
                var exception = new
                {
                    error = ResultFormatter.FormatErrorMessage(ModelState)
                };
                return(new BadRequestObjectResult(exception));
            }

            try
            {
                var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf");
                int timeoffsset    = Convert.ToInt32(Request.Headers["x-timezone-offset"]);
                var model          = await _service.ReadById(Id);

                if (model == null)
                {
                    return(StatusCode((int)HttpStatusCode.NotFound, "Not Found"));
                }
                else
                {
                    GarmentShippingLocalSalesNoteViewModel salesNote = await _salesNoteService.ReadById(model.localSalesNoteId);

                    Buyer        buyer       = _salesNoteService.GetBuyer(model.buyer.Id);
                    var          PdfTemplate = new GarmentLocalCoverLetterPdfTemplate();
                    MemoryStream stream      = PdfTemplate.GeneratePdfTemplate(model, salesNote, model.buyer, timeoffsset);

                    return(new FileStreamResult(stream, "application/pdf")
                    {
                        FileDownloadName = model.localCoverLetterNo + ".pdf"
                    });
                }
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        public MemoryStream GeneratePdfTemplate(GarmentLocalCoverLetterViewModel viewModel, GarmentShippingLocalSalesNoteViewModel salesNote, Buyer buyer, int timeoffset)
        {
            const int MARGIN = 20;

            Font header_font_bold       = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12);
            Font header_font            = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11);
            Font normal_font            = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            Font normal_font_underlined = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8, Font.UNDERLINE);
            Font bold_font  = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            Font small_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 5);
            //Font body_bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);

            Document     document = new Document(PageSize.A4, MARGIN, MARGIN, 140, MARGIN);
            MemoryStream stream   = new MemoryStream();
            PdfWriter    writer   = PdfWriter.GetInstance(document, stream);

            writer.PageEvent = new GarmentLocalCoverLetterPdfTemplatePageEvent();
            document.Open();

            #region title
            Paragraph title = new Paragraph("SURAT PENGANTAR", header_font_bold);
            title.Alignment = Element.ALIGN_CENTER;

            Paragraph no = new Paragraph(viewModel.localCoverLetterNo, bold_font);
            no.Alignment = Element.ALIGN_CENTER;

            Paragraph date = new Paragraph("Sukoharjo, " + viewModel.date.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")), normal_font);
            date.Alignment = Element.ALIGN_RIGHT;

            document.Add(title);
            document.Add(no);
            document.Add(date);
            document.Add(new Paragraph("\n", normal_font));
            #endregion

            #region header
            PdfPTable tableHeader = new PdfPTable(6);
            tableHeader.WidthPercentage = 100;
            tableHeader.SetWidths(new float[] { 4f, 1f, 6f, 4f, 1f, 3f });
            PdfPCell cellHeaderLeft = new PdfPCell()
            {
                MinimumHeight = 15, Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellHeaderRight = new PdfPCell()
            {
                MinimumHeight = 15, Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };

            cellHeaderLeft.Phrase = new Phrase("Kepada Yth.", normal_font);
            tableHeader.AddCell(cellHeaderLeft);
            cellHeaderLeft.Phrase = new Phrase(":", normal_font);
            tableHeader.AddCell(cellHeaderLeft);
            cellHeaderLeft.Phrase = new Phrase(viewModel.buyer.Name, normal_font);
            tableHeader.AddCell(cellHeaderLeft);
            cellHeaderRight.Phrase = new Phrase("No Nota Penjualan", normal_font);
            tableHeader.AddCell(cellHeaderRight);
            cellHeaderLeft.Phrase = new Phrase(":", normal_font);
            tableHeader.AddCell(cellHeaderLeft);
            cellHeaderLeft.Phrase = new Phrase(viewModel.noteNo, normal_font);
            tableHeader.AddCell(cellHeaderLeft);

            cellHeaderLeft.Phrase = new Phrase("Alamat", normal_font);
            tableHeader.AddCell(cellHeaderLeft);
            cellHeaderLeft.Phrase = new Phrase(":", normal_font);
            tableHeader.AddCell(cellHeaderLeft);
            cellHeaderLeft.Phrase = new Phrase(buyer.Address, normal_font);
            tableHeader.AddCell(cellHeaderLeft);
            cellHeaderRight.Phrase = new Phrase("Tgl Nota Penjualan", normal_font);
            tableHeader.AddCell(cellHeaderRight);
            cellHeaderLeft.Phrase = new Phrase(":", normal_font);
            tableHeader.AddCell(cellHeaderLeft);
            cellHeaderLeft.Phrase = new Phrase(salesNote.date.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")), normal_font);
            tableHeader.AddCell(cellHeaderLeft);

            tableHeader.SpacingAfter = 10;
            document.Add(tableHeader);
            #endregion

            document.Add(new Paragraph("Dengan hormat,", normal_font));
            document.Add(new Paragraph("\n", normal_font));
            document.Add(new Paragraph("      Bersama ini kami kirimkan kepada Bapak sejumlah barang dengan", normal_font));

            document.Add(new Paragraph("\n", normal_font));
            document.Add(new Paragraph("\n", normal_font));

            #region detail
            PdfPTable tableDetail = new PdfPTable(3);
            tableDetail.WidthPercentage = 80;
            tableDetail.SetWidths(new float[] { 1f, 1f, 1f });
            PdfPCell cellDetail = new PdfPCell()
            {
                MinimumHeight = 15, Border = Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };

            //double cbmtotal = 0;


            cellDetail.Phrase = new Phrase("Truck", normal_font);
            tableDetail.AddCell(cellDetail);
            cellDetail.Phrase = new Phrase("Nomor Polisi", normal_font);
            tableDetail.AddCell(cellDetail);
            cellDetail.Phrase = new Phrase("Pengemudi", normal_font);
            tableDetail.AddCell(cellDetail);

            cellDetail.Phrase = new Phrase(viewModel.truck, normal_font);
            tableDetail.AddCell(cellDetail);
            cellDetail.Phrase = new Phrase(viewModel.plateNumber, normal_font);
            tableDetail.AddCell(cellDetail);
            cellDetail.Phrase = new Phrase(viewModel.driver, normal_font);
            tableDetail.AddCell(cellDetail);

            tableDetail.SpacingAfter = 15;
            document.Add(tableDetail);
            #endregion

            #region marks
            PdfPTable tableMark = new PdfPTable(2);
            tableMark.WidthPercentage = 100;
            tableMark.SetWidths(new float[] { 1f, 6f });
            PdfPCell cellMark = new PdfPCell()
            {
                MinimumHeight = 15, Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };

            cellMark.Phrase = new Phrase("No Bea Cukai :", normal_font);
            tableMark.AddCell(cellMark);

            cellMark.Phrase = new Phrase(viewModel.bcNo, normal_font);
            tableMark.AddCell(cellMark);

            cellMark.Phrase = new Phrase("Tgl Bea Cukai :", normal_font);
            tableMark.AddCell(cellMark);

            cellMark.Phrase = new Phrase(viewModel.bcdate.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")), normal_font);
            tableMark.AddCell(cellMark);

            cellMark.Phrase = new Phrase("Shippig Mark :", normal_font);
            tableMark.AddCell(cellMark);

            cellMark.Phrase = new Phrase(viewModel.remark + "\n\n", normal_font);
            tableMark.AddCell(cellMark);

            tableMark.SpacingAfter = 15;
            document.Add(tableMark);
            #endregion

            document.Add(new Paragraph("Demikian harap diterima dengan baik dan terima kasih", normal_font));
            document.Add(new Paragraph("\n", normal_font));
            document.Add(new Paragraph("\n", normal_font));

            #region sign
            PdfPTable tableSign = new PdfPTable(5);
            tableSign.WidthPercentage = 100;
            tableSign.SetWidths(new float[] { 1f, 1f, 1f, 1f, 1f });
            PdfPCell cellSign = new PdfPCell()
            {
                MinimumHeight = 15, Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };

            //cellSign.Phrase = new Phrase("", normal_font);
            //tableSign.AddCell(cellSign);

            //cellSign.Phrase = new Phrase("SHIPPING STAF : "+ viewModel.shippingStaff.name, normal_font);
            //cellSign.Colspan = 3;
            //tableSign.AddCell(cellSign);


            cellSign.Phrase  = new Phrase("Pengemudi Truck, \n\n\n\n\n\n", normal_font);
            cellSign.Colspan = 1;
            tableSign.AddCell(cellSign);

            cellSign.Phrase  = new Phrase("Mengetahui, \n\n\n\n\n\n", normal_font);
            cellSign.Colspan = 2;
            tableSign.AddCell(cellSign);

            cellSign.Phrase  = new Phrase("\n\n\n\n\n\n", normal_font);
            cellSign.Colspan = 1;
            tableSign.AddCell(cellSign);


            cellSign.Phrase  = new Phrase("Hormat Kami, \n\n\n\n\n\n", normal_font);
            cellSign.Colspan = 1;
            tableSign.AddCell(cellSign);

            cellSign.Phrase = new Phrase("(                        )", normal_font);
            tableSign.AddCell(cellSign);

            cellSign.Phrase = new Phrase("(                        )", normal_font);
            tableSign.AddCell(cellSign);

            cellSign.Phrase = new Phrase("(                        )", normal_font);
            tableSign.AddCell(cellSign);

            cellSign.Phrase = new Phrase("(                        )", normal_font);
            tableSign.AddCell(cellSign);

            cellSign.Phrase = new Phrase($"( {viewModel.shippingStaff.name} )", normal_font);
            tableSign.AddCell(cellSign);

            cellSign.Phrase = new Phrase("\n", normal_font);
            tableSign.AddCell(cellSign);

            cellSign.Phrase = new Phrase("Audit", normal_font);
            tableSign.AddCell(cellSign);

            cellSign.Phrase = new Phrase("Sat Pam", normal_font);
            tableSign.AddCell(cellSign);

            cellSign.Phrase = new Phrase("Bagian Gudang", normal_font);
            tableSign.AddCell(cellSign);

            cellSign.Phrase = new Phrase("Shipping Staff", normal_font);
            tableSign.AddCell(cellSign);


            cellSign.Phrase = new Phrase("CATATAN : \n" +
                                         "1. Mohon bisa dikirim kembali Pengantar ini apabila barang sudah diterima \n" +
                                         "2. ....................................................", normal_font);
            cellSign.Colspan             = 3;
            cellSign.Rowspan             = 2;
            cellSign.HorizontalAlignment = Element.ALIGN_LEFT;
            tableSign.AddCell(cellSign);

            cellSign.Phrase              = new Phrase("Diterima, \n\n\n\n", normal_font);
            cellSign.Rowspan             = 1;
            cellSign.Colspan             = 2;
            cellSign.HorizontalAlignment = Element.ALIGN_CENTER;
            tableSign.AddCell(cellSign);

            cellSign.Phrase  = new Phrase("(                        )", normal_font);
            cellSign.Rowspan = 1;
            tableSign.AddCell(cellSign);

            document.Add(tableSign);
            #endregion

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

            return(stream);
        }