private GarmentPurchaseRequestViewModel FillGarmentPurchaseRequest(CostCalculationGarment costCalculation, Dictionary <long, string> productDicts)
        {
            GarmentPurchaseRequestViewModel garmentPurchaseRequest = new GarmentPurchaseRequestViewModel
            {
                PRType = "JOB ORDER",
                RONo   = costCalculation.RO_Number,
                SCId   = costCalculation.PreSCId,
                SCNo   = costCalculation.PreSCNo,
                Buyer  = new BuyerViewModel
                {
                    Id   = Convert.ToInt64(costCalculation.BuyerBrandId),
                    Code = costCalculation.BuyerBrandCode,
                    Name = costCalculation.BuyerBrandName
                },
                Article      = costCalculation.Article,
                Date         = DateTimeOffset.Now,
                ShipmentDate = costCalculation.DeliveryDate,
                Unit         = new UnitViewModel
                {
                    Id   = costCalculation.UnitId,
                    Code = costCalculation.UnitCode,
                    Name = costCalculation.UnitName
                },
                IsPosted = true,

                IsValidate    = true,
                ValidatedBy   = costCalculation.LastModifiedBy,
                ValidatedDate = costCalculation.LastModifiedUtc,

                Items = FillGarmentPurchaseRequestItems(costCalculation.CostCalculationGarment_Materials.ToList(), productDicts)
            };

            return(garmentPurchaseRequest);
        }
Example #2
0
        public void Should_Success_Validate_Data()
        {
            GarmentPurchaseRequestViewModel nullViewModel = new GarmentPurchaseRequestViewModel();

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

            GarmentPurchaseRequestViewModel viewModel = new GarmentPurchaseRequestViewModel
            {
                Buyer = new BuyerViewModel(),
                Unit  = new UnitViewModel(),
                Items = new List <GarmentPurchaseRequestItemViewModel>
                {
                    new GarmentPurchaseRequestItemViewModel(),
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Product     = new ProductViewModel(),
                        Uom         = new UomViewModel(),
                        Category    = new CategoryViewModel(),
                        BudgetPrice = -1
                    }
                }
            };

            Assert.True(viewModel.Validate(null).Count() > 0);
        }
Example #3
0
        public void Should_Success_Validate_Data()
        {
            GarmentPurchaseRequestViewModel nullViewModel = new GarmentPurchaseRequestViewModel();

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

            GarmentPurchaseRequestViewModel viewModel = new GarmentPurchaseRequestViewModel
            {
                Buyer = new BuyerViewModel(),
                Unit  = new UnitViewModel(),
                Items = new List <GarmentPurchaseRequestItemViewModel>
                {
                    new GarmentPurchaseRequestItemViewModel(),
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Product     = new ProductViewModel(),
                        Uom         = new UomViewModel(),
                        Category    = new CategoryViewModel(),
                        BudgetPrice = -1
                    }
                },
                IsValidatedMD1          = false,
                ValidatedMD1By          = null,
                ValidatedMD1Date        = DateTimeOffset.MinValue,
                IsValidatedMD2          = false,
                ValidatedMD2By          = null,
                ValidatedMD2Date        = DateTimeOffset.MinValue,
                IsValidatedPurchasing   = false,
                ValidatedPurchasingBy   = null,
                ValidatedPurchasingDate = DateTimeOffset.MinValue,
            };

            Assert.True(viewModel.Validate(null).Count() > 0);
        }
Example #4
0
        public async Task <IActionResult> Put(int id, [FromBody] GarmentPurchaseRequestViewModel ViewModel)
        {
            try
            {
                identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;

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

                validateService.Validate(ViewModel);

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

                await facade.Update(id, model, identityService.Username);

                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));
            }
        }
        private GarmentPurchaseRequestViewModel FillGarmentPurchaseRequest(CostCalculationGarment costCalculation, Dictionary <long, string> productDicts)
        {
            GarmentPurchaseRequestViewModel garmentPurchaseRequest = new GarmentPurchaseRequestViewModel
            {
                RONo  = costCalculation.RO_Number,
                Buyer = new BuyerViewModel
                {
                    Id   = Convert.ToInt64(costCalculation.BuyerBrandId),
                    Code = costCalculation.BuyerBrandCode,
                    Name = costCalculation.BuyerBrandName
                },
                Article      = costCalculation.Article,
                Date         = DateTimeOffset.Now,
                ShipmentDate = costCalculation.DeliveryDate,
                Unit         = new UnitViewModel
                {
                    Id   = costCalculation.UnitId,
                    Code = costCalculation.UnitCode,
                    Name = costCalculation.UnitName
                },
                Items = FillGarmentPurchaseRequestItems(costCalculation.CostCalculationGarment_Materials.ToList(), productDicts)
            };

            return(garmentPurchaseRequest);
        }
        private async Task <GarmentPurchaseRequestViewModel> GetGarmentPurchaseRequestByRONo(string roNo)
        {
            var httpResponseMessage = await httpClient.GetAsync($@"{APIEndpoint.AzurePurchasing}{GarmentPurchaseRequestUri}/by-rono/{roNo}");

            if (httpResponseMessage.StatusCode.Equals(HttpStatusCode.OK))
            {
                var result = httpResponseMessage.Content.ReadAsStringAsync().Result;
                Dictionary <string, object> resultDict = JsonConvert.DeserializeObject <Dictionary <string, object> >(result);

                var data = resultDict.SingleOrDefault(p => p.Key.Equals("data")).Value;

                GarmentPurchaseRequestViewModel garmentPurchaseRequestViewModel = JsonConvert.DeserializeObject <GarmentPurchaseRequestViewModel>(data.ToString());

                return(garmentPurchaseRequestViewModel);
            }
            else
            {
                return(null);
            }
        }
Example #7
0
        public IActionResult Get(int id)
        {
            try
            {
                var result = facade.ReadById(id);
                GarmentPurchaseRequestViewModel viewModel = mapper.Map <GarmentPurchaseRequestViewModel>(result);
                if (viewModel == null)
                {
                    throw new Exception("Invalid Id");
                }

                var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf");

                if (indexAcceptPdf < 0)
                {
                    Dictionary <string, object> Result =
                        new ResultFormatter(ApiVersion, General.OK_STATUS_CODE, General.OK_MESSAGE)
                        .Ok(viewModel);
                    return(Ok(Result));
                }
                else
                {
                    identityService.Token          = Request.Headers["Authorization"].First().Replace("Bearer ", "");
                    identityService.TimezoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First());

                    var stream = facade.GeneratePdf(serviceProvider, viewModel);

                    return(new FileStreamResult(stream, "application/pdf")
                    {
                        FileDownloadName = $"{viewModel.PRNo}.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));
            }
        }
Example #8
0
        public async Task Should_Success_Validate_Data_Duplicate()
        {
            GarmentPurchaseRequestFacade facade = new GarmentPurchaseRequestFacade(ServiceProvider, _dbContext(GetCurrentMethod()));
            var model = await dataUtil(facade, GetCurrentMethod()).GetTestData();

            GarmentPurchaseRequestViewModel viewModel = new GarmentPurchaseRequestViewModel();

            viewModel.RONo = model.RONo;

            Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.
            Setup(x => x.GetService(typeof(PurchasingDbContext)))
            .Returns(_dbContext(GetCurrentMethod()));

            ValidationContext validationContext = new ValidationContext(viewModel, serviceProvider.Object, null);

            var validationResultCreate = viewModel.Validate(validationContext).ToList();

            var errorDuplicateRONo = validationResultCreate.SingleOrDefault(r => r.ErrorMessage.Equals("RONo sudah ada"));

            Assert.NotNull(errorDuplicateRONo);

            viewModel.Id    = model.Id;
            viewModel.Items = new List <GarmentPurchaseRequestItemViewModel>();
            viewModel.Items.AddRange(model.Items.Select(i => new GarmentPurchaseRequestItemViewModel
            {
                PO_SerialNumber = i.PO_SerialNumber
            }));

            var validationResultUpdate = viewModel.Validate(validationContext).ToList();
            var errorItems             = validationResultUpdate.SingleOrDefault(r => r.MemberNames.Contains("Items"));
            List <Dictionary <string, object> > errorItemsMessage = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(errorItems.ErrorMessage);
            var errorDuplicatePO_SerialNumber = errorItemsMessage.FirstOrDefault(m => m.ContainsValue("PO SerialNumber sudah ada"));

            Assert.NotNull(errorDuplicatePO_SerialNumber);
        }
Example #9
0
        public IActionResult Get(string rono)
        {
            try
            {
                var result = facade.ReadByRONo(rono);
                GarmentPurchaseRequestViewModel viewModel = mapper.Map <GarmentPurchaseRequestViewModel>(result);
                if (viewModel == null)
                {
                    throw new Exception("Invalid rono");
                }

                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.OK_STATUS_CODE, General.OK_MESSAGE)
                    .Ok(viewModel);
                return(Ok(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));
            }
        }
Example #10
0
        public void Should_Success_Validate_Data_Master()
        {
            GarmentPurchaseRequestViewModel viewModel = new GarmentPurchaseRequestViewModel
            {
                PRType = "MASTER",
                Buyer  = new BuyerViewModel(),
                Unit   = new UnitViewModel(),
                Items  = new List <GarmentPurchaseRequestItemViewModel>
                {
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Category = new CategoryViewModel {
                            Name = "FABRIC"
                        },
                        PriceUom = new UomViewModel()
                    },
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Category = new CategoryViewModel {
                            Name = "FABRIC"
                        },
                        Composition = new GarmentProductViewModel {
                            Composition = "Composition"
                        },
                    },
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Category = new CategoryViewModel {
                            Name = "FABRIC"
                        },
                        Composition = new GarmentProductViewModel {
                            Composition = "Composition"
                        },
                        Const = new GarmentProductViewModel {
                            Const = "Const"
                        }
                    },
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Category = new CategoryViewModel {
                            Name = "FABRIC"
                        },
                        Composition = new GarmentProductViewModel {
                            Composition = "Composition"
                        },
                        Const = new GarmentProductViewModel {
                            Const = "Const"
                        },
                        Yarn = new GarmentProductViewModel {
                            Yarn = "Yarn"
                        },
                    },
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Category = new CategoryViewModel {
                            Name = "FABRIC"
                        },
                        Composition = new GarmentProductViewModel {
                            Composition = "Composition"
                        },
                        Const = new GarmentProductViewModel {
                            Const = "Const"
                        },
                        Yarn = new GarmentProductViewModel {
                            Yarn = "Yarn"
                        },
                        Width = new GarmentProductViewModel {
                            Width = "Width"
                        },
                    },
                }
            };

            Assert.True(viewModel.Validate(null).Count() > 0);
        }
        public static MemoryStream Generate(IServiceProvider serviceProvider, GarmentPurchaseRequestViewModel viewModel)
        {
            Font header_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12);
            Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 6);
            Font bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 6);

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

            document.Open();

            IdentityService identityService = (IdentityService)serviceProvider.GetService(typeof(IdentityService));
            IGarmentPurchaseRequestFacade garmentPurchaseRequestFacade = (IGarmentPurchaseRequestFacade)serviceProvider.GetService(typeof(IGarmentPurchaseRequestFacade));
            var salesContract = garmentPurchaseRequestFacade.GetGarmentPreSalesContract(viewModel.SCId);

            #region Header

            Paragraph title = new Paragraph("PT EFRATA RETAILINDO", normal_font)
            {
                Alignment = Element.ALIGN_LEFT
            };
            document.Add(title);

            Paragraph companyName = new Paragraph("BUDGET MASTER GARMENT", header_font)
            {
                Alignment = Element.ALIGN_LEFT
            };
            document.Add(companyName);

            #endregion

            PdfPCell cellLeftNoBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            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
            };

            #region Identity

            PdfPTable tableIdentity = new PdfPTable(4);
            tableIdentity.SetWidths(new float[] { 0.5f, 2f, 2.5f, 5f });

            cellLeftNoBorder.Phrase = new Phrase("RO", normal_font);
            tableIdentity.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase(": " + viewModel.RONo, normal_font);
            tableIdentity.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("LEAD TIME : 35", normal_font);
            tableIdentity.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase(string.Empty, normal_font);
            tableIdentity.AddCell(cellLeftNoBorder);

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

            #endregion

            #region TableContent

            PdfPTable tableContent = new PdfPTable(9);
            tableContent.SetWidths(new float[] { 36f, 116f, 100f, 175f, 90f, 68f, 153f, 132f, 130f });

            cellCenter.Phrase = new Phrase("NO", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("CATEGORIES", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("KODE PRODUK", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("DESCRIPTION", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("QUANTITY", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("UNIT", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("PRICE", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("AMOUNT", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("PO NUMBER", bold_font);
            tableContent.AddCell(cellCenter);

            double totalAmount = 0;
            int    indexItem   = 0;
            foreach (var item in viewModel.Items)
            {
                cellCenter.Phrase = new Phrase((++indexItem).ToString(), normal_font);
                tableContent.AddCell(cellCenter);

                cellLeft.Phrase = new Phrase(item.Category.Name, normal_font);
                tableContent.AddCell(cellLeft);

                cellLeft.Phrase = new Phrase(item.Product.Code, normal_font);
                tableContent.AddCell(cellLeft);

                cellLeft.Phrase = new Phrase(item.ProductRemark, normal_font);
                tableContent.AddCell(cellLeft);

                cellRight.Phrase = new Phrase(Math.Round(item.Quantity).ToString(), normal_font);
                tableContent.AddCell(cellRight);

                cellCenter.Phrase = new Phrase(item.Uom.Unit, normal_font);
                tableContent.AddCell(cellCenter);

                cellCenter.Phrase = new Phrase(string.Concat(item.BudgetPrice.ToString("n", new CultureInfo("id-ID")), "/", item.PriceUom.Unit), normal_font);
                tableContent.AddCell(cellCenter);

                var amount = item.Quantity * item.BudgetPrice / item.PriceConversion;
                cellRight.Phrase = new Phrase(amount.ToString("n", new CultureInfo("id-ID")), normal_font);
                tableContent.AddCell(cellRight);

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

                totalAmount += amount;
            }


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

            #endregion

            #region TableFooter

            PdfPTable tableFooter = new PdfPTable(5);
            tableFooter.SetWidths(new float[] { 121f, 302f, 57f, 304f, 217f });

            cellLeft.PaddingTop    = 7f;
            cellLeft.PaddingBottom = 7f;

            cellLeft.Phrase = new Phrase("PEMBERI KERJA", normal_font);
            tableFooter.AddCell(cellLeft);

            cellLeft.Phrase = new Phrase(/**salesContract.BuyerAgentCode + " - " + **/ salesContract.BuyerAgentName, normal_font);
            tableFooter.AddCell(cellLeft);

            tableFooter.AddCell(new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, Rowspan = 5
            });

            tableFooter.AddCell(new PdfPCell()
            {
                Padding             = 7f,
                Rowspan             = 3,
                Border              = cellLeft.Border,
                HorizontalAlignment = Element.ALIGN_LEFT,
                VerticalAlignment   = Element.ALIGN_TOP,
                Phrase              = new Phrase(string.Concat("TOTAL BUDGET : ", totalAmount.ToString("n", new CultureInfo("id-ID"))), normal_font)
            });

            tableFooter.AddCell(new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, Rowspan = 5
            });

            cellLeft.Phrase = new Phrase("ARTICLE", normal_font);
            tableFooter.AddCell(cellLeft);

            cellLeft.Phrase = new Phrase(viewModel.Article, normal_font);
            tableFooter.AddCell(cellLeft);

            cellLeft.Phrase = new Phrase("DESCRIPTION", normal_font);
            tableFooter.AddCell(cellLeft);

            cellLeft.Phrase = new Phrase(viewModel.Remark, normal_font);
            tableFooter.AddCell(cellLeft);

            cellLeft.Phrase = new Phrase("SHIPMENT", normal_font);
            tableFooter.AddCell(cellLeft);

            cellLeft.Phrase = new Phrase(viewModel.ShipmentDate.GetValueOrDefault().ToOffset(new TimeSpan(identityService.TimezoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font);
            tableFooter.AddCell(cellLeft);

            tableFooter.AddCell(new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, Rowspan = 2
            });

            /**cellLeft.Phrase = new Phrase("BUYER BRAND", normal_font);
             * tableFooter.AddCell(cellLeft);
             *
             * cellLeft.Phrase = new Phrase(viewModel.Buyer.Code + " - " + viewModel.Buyer.Name, normal_font);
             * tableFooter.AddCell(cellLeft);**/


            PdfPCell cellfooter = new PdfPCell(tableFooter);
            tableFooter.ExtendLastRow = false;
            document.Add(tableFooter);

            #endregion

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

            return(stream);
        }