public async Task <IActionResult> Put(int id, [FromBody] GarmentUnitExpenditureNoteViewModel ViewModel)
        {
            try
            {
                identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;

                identityService.TimezoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First());

                IValidateService validateService = (IValidateService)serviceProvider.GetService(typeof(IValidateService));

                validateService.Validate(ViewModel);

                var model = mapper.Map <GarmentUnitExpenditureNote>(ViewModel);

                await facade.Update(id, model);

                return(NoContent());
            }
            catch (ServiceValidationExeption e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE)
                    .Fail(e);
                return(BadRequest(Result));
            }
            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));
            }
        }
Exemple #2
0
        public async Task <IActionResult> PutIsPreparingFalse(int id, [FromBody] GarmentUnitExpenditureNoteViewModel ViewModel)
        {
            try
            {
                identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;

                ViewModel.IsPreparing = false;

                var model = mapper.Map <GarmentUnitExpenditureNote>(ViewModel);

                await facade.UpdateIsPreparing(id, model);

                return(NoContent());
            }
            catch (ServiceValidationExeption e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE)
                    .Fail(e);
                return(BadRequest(Result));
            }
            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));
            }
        }
        public async Task <IActionResult> Post([FromBody] GarmentUnitExpenditureNoteViewModel viewModel)
        {
            try
            {
                identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;

                if (viewModel.Items != null)
                {
                    viewModel.Items = viewModel.Items.Where(s => s.IsSave).ToList();
                }

                identityService.TimezoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First());

                IValidateService validateService = (IValidateService)serviceProvider.GetService(typeof(IValidateService));
                validateService.Validate(viewModel);

                var Model = mapper.Map <GarmentUnitExpenditureNote>(viewModel);

                await facade.Create(Model);

                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE)
                    .Ok();
                return(Created(String.Concat(Request.Path, "/", 0), Result));
            }
            catch (ServiceValidationExeption e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE)
                    .Fail(e);
                return(BadRequest(Result));
            }
            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));
            }
        }
Exemple #4
0
        public async Task Should_Success_Validate_Data()
        {
            GarmentUnitExpenditureNoteViewModel viewModel = new GarmentUnitExpenditureNoteViewModel {
            };

            Assert.True(viewModel.Validate(null).Count() > 0);

            GarmentUnitExpenditureNoteViewModel viewModelCheckExpenditureDate = new GarmentUnitExpenditureNoteViewModel
            {
                ExpenditureDate = DateTimeOffset.Now
            };

            Assert.True(viewModelCheckExpenditureDate.Validate(null).Count() > 0);

            GarmentUnitExpenditureNoteViewModel viewModelCheckUnitDeliveryOrder = new GarmentUnitExpenditureNoteViewModel
            {
                ExpenditureDate = DateTimeOffset.Now,
                UnitDONo        = "UnitDONO123",
            };

            Assert.True(viewModelCheckUnitDeliveryOrder.Validate(null).Count() > 0);

            GarmentUnitExpenditureNoteViewModel viewModelCheckItemsCount = new GarmentUnitExpenditureNoteViewModel {
                UnitDOId = 1
            };

            Assert.True(viewModelCheckItemsCount.Validate(null).Count() > 0);

            Mock <IGarmentUnitDeliveryOrderFacade> garmentUnitDeliveryOrderFacadeMock = new Mock <IGarmentUnitDeliveryOrderFacade>();

            Mock <IGarmentUnitExpenditureNoteFacade> garmentUnitExpenditureNoteFacadeMock = new Mock <IGarmentUnitExpenditureNoteFacade>();

            garmentUnitDeliveryOrderFacadeMock.Setup(s => s.ReadById(It.IsAny <int>()))
            .Returns(new GarmentUnitDeliveryOrder {
                Id = 1,

                Items = new List <GarmentUnitDeliveryOrderItem>
                {
                    new GarmentUnitDeliveryOrderItem
                    {
                        Id       = 1,
                        Quantity = 4
                    },
                }
            });

            var facade = new GarmentUnitExpenditureNoteFacade(GetServiceProvider(), _dbContext(GetCurrentMethod()));
            Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.
            Setup(x => x.GetService(typeof(IGarmentUnitDeliveryOrderFacade)))
            .Returns(garmentUnitDeliveryOrderFacadeMock.Object);
            serviceProvider.Setup(x => x.GetService(typeof(PurchasingDbContext)))
            .Returns(_dbContext(GetCurrentMethod()));
            var data = await dataUtil(facade, GetCurrentMethod()).GetTestData();

            var item = data.Items.First();
            var garmentUnitExpenditureNote = new GarmentUnitExpenditureNoteViewModel
            {
                UnitDOId = 1,
                Items    = new List <GarmentUnitExpenditureNoteItemViewModel>
                {
                    new GarmentUnitExpenditureNoteItemViewModel
                    {
                        Id           = item.Id,
                        UnitDOItemId = 1,
                        Quantity     = 10,
                        IsSave       = true,
                    },

                    new GarmentUnitExpenditureNoteItemViewModel
                    {
                        Id           = item.Id,
                        UnitDOItemId = 1,
                        Quantity     = 100,
                        IsSave       = true,
                    },

                    new GarmentUnitExpenditureNoteItemViewModel
                    {
                        Id           = item.Id,
                        UnitDOItemId = 1,
                        Quantity     = 0,
                        IsSave       = true
                    },
                }
            };

            Mock <IGarmentUnitExpenditureNoteFacade> garmentUnitExpenditreMock = new Mock <IGarmentUnitExpenditureNoteFacade>();

            garmentUnitExpenditreMock.Setup(s => s.ReadById(1))
            .Returns(garmentUnitExpenditureNote);
            garmentUnitExpenditreMock.Setup(s => s.ReadById(It.IsAny <int>()))
            .Returns(garmentUnitExpenditureNote);

            serviceProvider.
            Setup(x => x.GetService(typeof(IGarmentUnitExpenditureNoteFacade)))
            .Returns(garmentUnitExpenditreMock.Object);
            System.ComponentModel.DataAnnotations.ValidationContext garmentUnitDeliveryOrderValidate = new System.ComponentModel.DataAnnotations.ValidationContext(garmentUnitExpenditureNote, serviceProvider.Object, null);
            Assert.True(garmentUnitExpenditureNote.Validate(garmentUnitDeliveryOrderValidate).Count() > 0);
        }
Exemple #5
0
        public static MemoryStream GeneratePdfTemplate(IServiceProvider serviceProvider, GarmentUnitExpenditureNoteViewModel viewModel)
        {
            Font header_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 15);
            Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10);
            Font bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10);

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

            document.Open();

            IGarmentUnitDeliveryOrderFacade garmentUnitDeliveryOrderFacade = (IGarmentUnitDeliveryOrderFacade)serviceProvider.GetService(typeof(IGarmentUnitDeliveryOrderFacade));
            var garmentUnitDeliveryOrder = garmentUnitDeliveryOrderFacade.ReadById((int)viewModel.UnitDOId);

            IdentityService identityService = (IdentityService)serviceProvider.GetService(typeof(IdentityService));

            #region Header


            string    formString = "FM-00-AD-09-006B/R1";
            Paragraph form       = new Paragraph(formString, bold_font)
            {
                Alignment = Element.ALIGN_RIGHT
            };
            document.Add(form);

            string    titleString = "BON PENGELUARAN BARANG";
            Paragraph title       = new Paragraph(titleString, header_font)
            {
                Alignment = Element.ALIGN_CENTER
            };
            document.Add(title);

            string    companyNameString = "PT DAN LIRIS";
            Paragraph companyName       = new Paragraph(companyNameString, bold_font)
            {
                Alignment = Element.ALIGN_LEFT
            };
            document.Add(companyName);

            string    companyAddressString = "BANARAN, GROGOL, SUKOHARJO";
            Paragraph companyAddress       = new Paragraph(companyAddressString, bold_font)
            {
                Alignment = Element.ALIGN_LEFT
            };
            document.Add(companyAddress);

            string    companyPostalCodeString = "PO. Box. 166 Solo - 57100 Indonesia";
            Paragraph companyPostalCode       = new Paragraph(companyPostalCodeString, bold_font)
            {
                Alignment = Element.ALIGN_LEFT
            };
            document.Add(companyPostalCode);

            #endregion

            #region Identity

            PdfPTable tableIdentity = new PdfPTable(4);
            tableIdentity.SetWidths(new float[] { 3f, 4f, 3f, 4f });
            PdfPCell cellIdentityContentLeft = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };

            cellIdentityContentLeft.Phrase = new Phrase("No. Bukti Pengeluaran", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.UENNo, normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase("Tgl. Bukti Pengeluaran", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase(": " + DateTimeOffset.Now.ToOffset(new TimeSpan(identityService.TimezoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase("Tgl. Pengeluaran", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.ExpenditureDate.ToOffset(new TimeSpan(identityService.TimezoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase("Gudang", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.Storage.name, normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase("Tujuan Pengeluaran", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.ExpenditureType, normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase("Konveksi", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.UnitSender.Name, normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase("Dasar Pengeluaran", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.UnitDONo, normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase("RO Tujuan", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase(": " + garmentUnitDeliveryOrder.RONo, normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase("", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase("", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase("No Artikel", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase(": " + garmentUnitDeliveryOrder.Article, normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);

            PdfPCell cellIdentity = new PdfPCell(tableIdentity);
            tableIdentity.ExtendLastRow = false;
            tableIdentity.SpacingAfter  = 10f;
            tableIdentity.SpacingBefore = 20f;
            document.Add(tableIdentity);

            #endregion

            #region TableContent

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

            PdfPTable tableContent = new PdfPTable(5);
            tableContent.SetWidths(new float[] { 2f, 2f, 7f, 3f, 5f });

            cellCenter.Phrase = new Phrase("Kode", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Nama", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Keterangan Barang", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Jumlah", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Satuan", bold_font);
            tableContent.AddCell(cellCenter);

            int indexItem = 0;
            foreach (var item in viewModel.Items)
            {
                cellLeft.Phrase = new Phrase($"{item.ProductCode}", normal_font);
                tableContent.AddCell(cellLeft);

                cellLeft.Phrase = new Phrase($"{item.ProductName}", normal_font);
                tableContent.AddCell(cellLeft);

                cellCenter.Phrase = new Phrase($"{item.ProductRemark}", normal_font);
                tableContent.AddCell(cellCenter);

                cellCenter.Phrase = new Phrase(item.Quantity.ToString(), normal_font);
                tableContent.AddCell(cellCenter);

                cellCenter.Phrase = new Phrase($"{item.UomUnit}", normal_font);
                tableContent.AddCell(cellCenter);
            }


            PdfPCell cellContent = new PdfPCell(tableContent);
            tableContent.ExtendLastRow = false;
            tableContent.SpacingAfter  = 20f;
            document.Add(tableContent);

            #endregion

            #region TableSignature

            PdfPTable tableSignature = new PdfPTable(3);

            PdfPCell cellSignatureContentLeft = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellSignatureContent = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };

            cellSignatureContent.Phrase = new Phrase("Yang Menerima\n\n\n\n\n\n\n(  _____________________  )", normal_font);
            tableSignature.AddCell(cellSignatureContent);
            cellSignatureContent.Phrase = new Phrase("Mengetahui\n\n\n\n\n\n\n(  _____________________  )", normal_font);
            tableSignature.AddCell(cellSignatureContent);
            cellSignatureContent.Phrase = new Phrase("Diserahkan Oleh\n\n\n\n\n\n\n(  _____________________  )", normal_font);
            tableSignature.AddCell(cellSignatureContent);

            cellSignatureContentLeft.Phrase = new Phrase($"\n\nDicetak Tanggal {DateTimeOffset.Now.ToOffset(new TimeSpan(identityService.TimezoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", normal_font);
            tableSignature.AddCell(cellSignatureContentLeft);
            cellSignatureContent.Phrase = new Phrase(" ", normal_font);
            tableSignature.AddCell(cellSignatureContent);
            cellSignatureContent.Phrase = new Phrase(" ", normal_font);
            tableSignature.AddCell(cellSignatureContent);

            PdfPCell cellSignature = new PdfPCell(tableSignature); // dont remove
            tableSignature.ExtendLastRow = false;
            tableSignature.SpacingBefore = 20f;
            tableSignature.SpacingAfter  = 20f;
            document.Add(tableSignature);

            #endregion

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

            return(stream);
        }