public async override Task Should_Success_Update() { string testName = GetCurrentMethod(); var dbContext = DbContext(testName); var serviceProvider = GetServiceProviderMock(dbContext).Object; GarmentPackingListRepository repoPL = new GarmentPackingListRepository(dbContext, serviceProvider); GarmentPackingListDataUtil utilPL = new GarmentPackingListDataUtil(repoPL); GarmentPackingListModel dataPL = utilPL.GetModel(); var dataPackingList = await repoPL.InsertAsync(dataPL); GarmentShippingInvoiceRepository repo = new GarmentShippingInvoiceRepository(dbContext, serviceProvider); GarmentShippingInvoiceRepository repo2 = new GarmentShippingInvoiceRepository(dbContext, serviceProvider); GarmentShippingInvoiceDataUtil invoiceDataUtil = new GarmentShippingInvoiceDataUtil(repo, utilPL); GarmentShippingInvoiceModel oldModel = invoiceDataUtil.GetModels(); oldModel.PackingListId = dataPL.Id; await repo.InsertAsync(oldModel); var model = repo.ReadAll().FirstOrDefault(); var data = await repo.ReadByIdAsync(model.Id); data.SetFrom("aaaa", data.LastModifiedBy, data.LastModifiedAgent); data.SetTo("bbb", data.LastModifiedBy, data.LastModifiedAgent); data.SetConsignee("dsdsds", data.LastModifiedBy, data.LastModifiedAgent); data.SetShippingPer("model.ShippingPer", data.LastModifiedBy, data.LastModifiedAgent); data.SetSailingDate(DateTimeOffset.Now.AddDays(3), data.LastModifiedBy, data.LastModifiedAgent); data.SetConfirmationOfOrderNo("dada", data.LastModifiedBy, data.LastModifiedAgent); data.SetShippingStaffId(4, data.LastModifiedBy, data.LastModifiedAgent); data.SetShippingStaff(" model.ShippingStaff", data.LastModifiedBy, data.LastModifiedAgent); data.SetFabricTypeId(2, data.LastModifiedBy, data.LastModifiedAgent); data.SetFabricType("model.FabricType", data.LastModifiedBy, data.LastModifiedAgent); data.SetBankAccountId(3, data.LastModifiedBy, data.LastModifiedAgent); data.SetBankAccount("model.BankAccount", data.LastModifiedBy, data.LastModifiedAgent); data.SetPaymentDue(33, data.LastModifiedBy, data.LastModifiedAgent); data.SetPEBNo("model.PEBNo", data.LastModifiedBy, data.LastModifiedAgent); data.SetPEBDate(DateTimeOffset.Now.AddDays(3), data.LastModifiedBy, data.LastModifiedAgent); data.SetNPENo("model.NPENo", data.LastModifiedBy, data.LastModifiedAgent); data.SetNPEDate(DateTimeOffset.Now.AddDays(3), data.LastModifiedBy, data.LastModifiedAgent); data.SetBL("model.BL", data.LastModifiedBy, data.LastModifiedAgent); data.SetBLDate(DateTimeOffset.Now.AddDays(3), data.LastModifiedBy, data.LastModifiedAgent); data.SetCO("model.CO", data.LastModifiedBy, data.LastModifiedAgent); data.SetCODate(DateTimeOffset.Now.AddDays(3), data.LastModifiedBy, data.LastModifiedAgent); data.SetCOTP("model.COTP", data.LastModifiedBy, data.LastModifiedAgent); data.SetCOTPDate(DateTimeOffset.Now.AddDays(3), data.LastModifiedBy, data.LastModifiedAgent); data.SetDescription("model.Description", data.LastModifiedBy, data.LastModifiedAgent); data.SetRemark("model.Remark", data.LastModifiedBy, data.LastModifiedAgent); data.SetCPrice("cprice", data.LastModifiedBy, data.LastModifiedAgent); data.SetMemo("model.Memo", data.LastModifiedBy, data.LastModifiedAgent); data.SetAmountToBePaid(500, data.LastModifiedBy, data.LastModifiedAgent); data.SetTotalAmount(2, data.LastModifiedBy, data.LastModifiedAgent); data.SetConsigneeAddress("updated", data.LastModifiedBy, data.LastModifiedAgent); data.SetDeliverTo("updated", data.LastModifiedBy, data.LastModifiedAgent); data.SetInvoiceDate(DateTime.Now.AddDays(8), data.LastModifiedBy, data.LastModifiedAgent); data.Items.Add(new GarmentShippingInvoiceItemModel("ro", "scno", 1, "buyerbrandname", 1, 1, "comocode", "comoname", "comodesc", "comodesc", "comodesc", "comodesc", 1, "pcs", 10, 10, 100, "usd", 1, "unitcode", 3, 1)); foreach (var item in data.Items) { item.SetPrice(1039, item.LastModifiedBy, item.LastModifiedAgent); item.SetComodityDesc("hahhahah", item.LastModifiedBy, item.LastModifiedAgent); item.SetDesc2("hahhahah", item.LastModifiedBy, item.LastModifiedAgent); item.SetDesc3("hahhahah", item.LastModifiedBy, item.LastModifiedAgent); item.SetDesc4("hahhahah", item.LastModifiedBy, item.LastModifiedAgent); item.SetCMTPrice(56000, item.LastModifiedBy, item.LastModifiedAgent); item.SetUomId(2, item.LastModifiedBy, item.LastModifiedAgent); item.SetUomUnit("sss", item.LastModifiedBy, item.LastModifiedAgent); } var ajdData = data.GarmentShippingInvoiceAdjustment.FirstOrDefault(); data.GarmentShippingInvoiceAdjustment.Add(new GarmentShippingInvoiceAdjustmentModel(data.Id, "ddd", 1000, 1)); ajdData.SetAdjustmentDescription("dsds", ajdData.LastModifiedBy, ajdData.LastModifiedAgent); ajdData.SetAdjustmentValue(10000 + ajdData.AdjustmentValue, ajdData.LastModifiedBy, ajdData.LastModifiedAgent); ajdData.SetAdditionalChargesId(1 + ajdData.AdditionalChargesId, ajdData.LastModifiedBy, ajdData.LastModifiedAgent); var unitData = data.GarmentShippingInvoiceUnit.FirstOrDefault(); data.GarmentShippingInvoiceUnit.Add(new GarmentShippingInvoiceUnitModel(1, "ddd", 100, 1000)); unitData.SetUnitCode("dsdsasda", unitData.LastModifiedBy, ajdData.LastModifiedAgent); unitData.SetUnitId(unitData.UnitId + 1, unitData.LastModifiedBy, ajdData.LastModifiedAgent); unitData.SetQuantityPercentage(unitData.QuantityPercentage + 1, unitData.LastModifiedBy, ajdData.LastModifiedAgent); unitData.SetAmountPercentage(unitData.AmountPercentage + 1, unitData.LastModifiedBy, ajdData.LastModifiedAgent); var result = await repo2.UpdateAsync(data.Id, data); Assert.NotEqual(0, result); }
public void GenerateExcel_Success() { var items = new List <GarmentShippingInvoiceItemModel> { new GarmentShippingInvoiceItemModel("", "", 1, "", 1, 1, "", "", "", "comodesc", "comodesc", "comodesc", 1, "uom1", 1, 1, 1, "", 1, "C10", 1) { GarmentShippingInvoiceId = 1 }, new GarmentShippingInvoiceItemModel("", "", 1, "", 1, 1, "", "", "", "comodesc", "comodesc", "comodesc", 2, "Uom2", 1, 1, 1, "", 1, "C10", 1) { GarmentShippingInvoiceId = 1 }, new GarmentShippingInvoiceItemModel("", "", 1, "", 1, 1, "", "", "", "comodesc", "comodesc", "comodesc", 2, "Uom2", 1, 1, 1, "", 1, "B10", 1) { GarmentShippingInvoiceId = 1 }, }; var invoiceUnitModels = new HashSet <GarmentShippingInvoiceUnitModel> { new GarmentShippingInvoiceUnitModel(1, "unitcode", 3, 1) { Id = 1 } }; var model = new GarmentShippingInvoiceModel(1, "", DateTimeOffset.Now, "", "", 1, "A99", "", "", "", "", 1, "", "", DateTimeOffset.Now, "", 1, "", 1, "", 1, "", 1, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", items, 1, "", "", "", false, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", DateTimeOffset.Now, null, 1, "", "", invoiceUnitModels) { Id = 1 }; var model2 = new GarmentPackingListModel("", "", "DL", 1, "", DateTimeOffset.Now, "", "", DateTimeOffset.Now, "", 1, "", "", "", "", "", DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, true, true, "", "", "", null, 1, 1, 1, 1, null, "", "", "", "", "", "", "", true, true, 1, "", GarmentPackingListStatusEnum.CREATED, "") { Id = 1 }; var repoMock = new Mock <IGarmentShippingInvoiceRepository>(); repoMock.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingInvoiceModel>() { model }.AsQueryable()); var repoMock1 = new Mock <IGarmentShippingInvoiceItemRepository>(); repoMock1.Setup(s => s.ReadAll()) .Returns(items.AsQueryable()); var repoMock2 = new Mock <IGarmentPackingListRepository>(); repoMock2.Setup(s => s.ReadAll()) .Returns(new List <GarmentPackingListModel>() { model2 }.AsQueryable()); var service = GetService(GetServiceProvider(repoMock.Object, repoMock1.Object, repoMock2.Object).Object); var result = service.GenerateExcel(null, DateTime.MinValue, DateTime.Now, 7); Assert.NotNull(result); }
public void GetReportData_Success() { var model1 = new GarmentPackingListModel("", "", "DL", 1, "", DateTimeOffset.Now, "", "", DateTimeOffset.Now, "", 1, "", "", "", "", "", DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, false, false, "", "", "", null, 1, 1, 1, 1, null, "", "", "", "", "", "", "", false, false, 1, "", GarmentPackingListStatusEnum.CREATED, "", false, "") { Id = 1 }; var model2 = new GarmentShippingInvoiceModel(1, "", DateTimeOffset.Now, "", "", 1, "A99", "", "", "", "", 1, "", "", DateTimeOffset.Now, "", 1, "", 1, "", 1, "", 1, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", "", null, 1, "", "", "", false, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", DateTimeOffset.Now, null, 1, "", "", null) { Id = 1 }; var iteminv = new List <GarmentShippingInvoiceItemModel> { new GarmentShippingInvoiceItemModel("", "", 1, "", 1, 1, "", "", "", "", "", "", 1, "", 1, 1, 1, "", 1, "C10", 1, 1) { GarmentShippingInvoiceId = 1 }, new GarmentShippingInvoiceItemModel("", "", 1, "", 1, 1, "", "", "", "", "", "", 1, "", 1, 1, 1, "", 1, "C10", 1, 2) { GarmentShippingInvoiceId = 1 }, }; var itemadj = new List <GarmentShippingInvoiceAdjustmentModel> { new GarmentShippingInvoiceAdjustmentModel(1, "", 100, 1) { GarmentShippingInvoiceId = 1 }, new GarmentShippingInvoiceAdjustmentModel(1, "", 25, 1) { GarmentShippingInvoiceId = 1 }, }; var model3 = new GarmentShippingCoverLetterModel(1, 1, "", DateTimeOffset.Now, 1, "", "", "", "", "", "", "", DateTimeOffset.Now, 1, "", "", 1, 1, 1, 1, 1, "", "", "", "", "", "", "", "", "", "", DateTimeOffset.Now, "", 1, ""); var model4 = new GarmentShippingCreditAdviceModel(1, 1, "", DateTimeOffset.Now, 1, 1, "", "", "", true, "", 1, 1, "", DateTimeOffset.Now, DateTimeOffset.Now, "", 1, 1, 1, DateTimeOffset.Now, 1, 1, 1, 1, 1, 1, 1, "", 1, "", "", 1, "", "", 1, 1, 1, DateTimeOffset.Now, "", DateTimeOffset.Now, 1, "", DateTimeOffset.Now, 1, DateTimeOffset.Now, ""); var repoMock1 = new Mock <IGarmentPackingListRepository>(); repoMock1.Setup(s => s.ReadAll()) .Returns(new List <GarmentPackingListModel>() { model1 }.AsQueryable()); var repoMock2 = new Mock <IGarmentShippingInvoiceRepository>(); repoMock2.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingInvoiceModel>() { model2 }.AsQueryable()); var repoMock3 = new Mock <IGarmentShippingInvoiceItemRepository>(); repoMock3.Setup(s => s.ReadAll()) .Returns(iteminv.AsQueryable()); var repoMock4 = new Mock <IGarmentShippingInvoiceAdjustmentRepository>(); repoMock4.Setup(s => s.ReadAll()) .Returns(itemadj.AsQueryable()); var repoMock5 = new Mock <IGarmentCoverLetterRepository>(); repoMock5.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingCoverLetterModel>() { model3 }.AsQueryable()); var repoMock6 = new Mock <IGarmentShippingCreditAdviceRepository>(); repoMock6.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingCreditAdviceModel>() { model4 }.AsQueryable()); var service = GetService(GetServiceProvider(repoMock1.Object, repoMock2.Object, repoMock3.Object, repoMock4.Object, repoMock5.Object, repoMock6.Object).Object); var result = service.GetReportData(model2.BuyerAgentCode, null, DateTime.MinValue, DateTime.MaxValue, 0); Assert.NotEmpty(result.ToList()); }
public void GetReportData_Success() { var model = new GarmentShippingInvoiceModel(1, "", DateTimeOffset.Now, "", "", 1, "A99", "", "", "", "", 1, "", "", DateTimeOffset.Now, "", 1, "", 1, "", 1, "", 1, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", "", null, 1, "", "", "", false, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", DateTimeOffset.Now, null, 1, "", "", null) { Id = 1 }; var model1 = new GarmentPackingListModel("", "", "DL", 1, "", DateTimeOffset.Now, "", "", DateTimeOffset.Now, "", 1, "", "", "", "", "", DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, false, false, "", "", "", null, 1, 1, 1, 1, null, "", "", "", "", "", "", "", false, false, 1, "", GarmentPackingListStatusEnum.CREATED, "", false, "") { Id = 1 }; var model2 = new GarmentShippingCreditAdviceModel(1, 1, "", DateTimeOffset.Now, 1, 1, "", "", true, "", 1, 1, "", DateTimeOffset.Now, DateTimeOffset.Now, "", 1, 1, 1, DateTimeOffset.Now, 1, 1, 1, 1, 1, 1, 1, "", 1, "", "", 1, "", "", 1, 1, 1, DateTimeOffset.Now, "", DateTimeOffset.Now, 1, "", DateTimeOffset.Now, 1, DateTimeOffset.Now, ""); var model3 = new GarmentShippingInvoiceItemModel("", "", 1, "", 1, 1, "", "", "", "comodesc", "comodesc", "comodesc", 1, "", 1, 1, 1, "", 1, "C10", 1, 1) { GarmentShippingInvoiceId = 1 }; var repoMock = new Mock <IGarmentShippingInvoiceRepository>(); repoMock.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingInvoiceModel>() { model }.AsQueryable()); var repoMock1 = new Mock <IGarmentPackingListRepository>(); repoMock1.Setup(s => s.ReadAll()) .Returns(new List <GarmentPackingListModel>() { model1 }.AsQueryable()); var repoMock2 = new Mock <IGarmentShippingCreditAdviceRepository>(); repoMock2.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingCreditAdviceModel>() { model2 }.AsQueryable()); var repoMock3 = new Mock <IGarmentShippingInvoiceItemRepository>(); repoMock3.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingInvoiceItemModel>() { model3 }.AsQueryable()); var httpMock = new Mock <IHttpClientService>(); httpMock.Setup(s => s.SendAsync(HttpMethod.Get, It.IsAny <string>(), It.IsAny <HttpContent>())) .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(new { data = new List <GarmentCurrency> { new GarmentCurrency() { code = "usd" } } })) }); var spMock = GetServiceProvider(repoMock.Object, repoMock1.Object, repoMock2.Object, repoMock3.Object); spMock.Setup(s => s.GetService(typeof(IHttpClientService))) .Returns(httpMock.Object); var service = GetService(spMock.Object); var result = service.GetReportData(model.BuyerAgentCode, DateTime.MinValue, DateTime.MaxValue, 0); Assert.NotEmpty(result.Data); }
public void GetReportData_Success() { var packinglistmodel = new GarmentPackingListModel("", "", "DL", 1, "", DateTimeOffset.Now, "", "", DateTimeOffset.Now, "", 1, "", "", "", "USA", "", DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, true, true, "", "", "", null, 1, 1, 1, 1, null, "", "", "", "", "", "", "", true, true, 1, "", GarmentPackingListStatusEnum.CREATED, "") { Id = 1 }; var invoiceItemModels = new List <GarmentShippingInvoiceItemModel> { new GarmentShippingInvoiceItemModel("ro", "scno", 1, "buyerbrandname", 10, 1, "comocode", "comoname", "comodesc", "comodesc", "comodesc", "comodesc", 1, "PCS", 10, 10, 100, "usd", 1, "unitcode", 3) { GarmentShippingInvoiceId = 1 }, new GarmentShippingInvoiceItemModel("ro", "scno", 1, "buyerbrandname", 15, 2, "comocode2", "comoname2", "comodesc2", "comodesc", "comodesc", "comodesc", 2, "SETS", 20, 20, 300, "usd", 1, "unitcode", 3) { GarmentShippingInvoiceId = 1 }, new GarmentShippingInvoiceItemModel("ro", "scno", 2, "buyerbrandname2", 10, 1, "comocode", "comoname", "comodesc", "comodesc", "comodesc", "comodesc", 1, "PCS", 10, 10, 100, "usd", 1, "unitcode", 3) { GarmentShippingInvoiceId = 1 }, new GarmentShippingInvoiceItemModel("ro", "scno", 2, "buyerbrandname2", 15, 2, "comocode2", "comoname2", "comodesc2", "comodesc", "comodesc", "comodesc", 2, "SETS", 20, 20, 300, "usd", 1, "unitcode", 3) { GarmentShippingInvoiceId = 1 } }; var invoiceUnitModels = new HashSet <GarmentShippingInvoiceUnitModel> { new GarmentShippingInvoiceUnitModel(1, "unitcode", 3, 1) { Id = 1 } }; var invoiceModel = new GarmentShippingInvoiceModel(1, "invoiceno", DateTimeOffset.Now, "from", "to", 1, "buyercode", "buyername", "consignee", "lcno", "issuedby", 1, "sectioncode", "shippingper", DateTimeOffset.Now, "confNo", 1, "staff", 1, "cottn", 1, "mandiri", 10, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", invoiceItemModels, 1000, "23", "dsdsds", "memo", false, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", DateTimeOffset.Now, null, 100000, "aa", "aa", invoiceUnitModels) { Id = 1, }; var repoMock = new Mock <IGarmentShippingInvoiceRepository>(); repoMock.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingInvoiceModel>() { invoiceModel }.AsQueryable()); var repoMock1 = new Mock <IGarmentShippingInvoiceItemRepository>(); repoMock1.Setup(s => s.ReadAll()) .Returns(invoiceItemModels.AsQueryable()); var repoMock2 = new Mock <IGarmentPackingListRepository>(); repoMock2.Setup(s => s.ReadAll()) .Returns(new List <GarmentPackingListModel>() { packinglistmodel }.AsQueryable()); var service = GetService(GetServiceProvider(repoMock.Object, repoMock1.Object, repoMock2.Object).Object); var result = service.GetReportData(packinglistmodel.TruckingDate.Year); Assert.NotEmpty(result); }
protected GarmentPackingListViewModel MapToViewModel(GarmentPackingListModel model) { var vm = new GarmentPackingListViewModel() { Active = model.Active, Id = model.Id, CreatedAgent = model.CreatedAgent, CreatedBy = model.CreatedBy, CreatedUtc = model.CreatedUtc, DeletedAgent = model.DeletedAgent, DeletedBy = model.DeletedBy, DeletedUtc = model.DeletedUtc, IsDeleted = model.IsDeleted, LastModifiedAgent = model.LastModifiedAgent, LastModifiedBy = model.LastModifiedBy, LastModifiedUtc = model.LastModifiedUtc, InvoiceNo = model.InvoiceNo, PackingListType = model.PackingListType, InvoiceType = model.InvoiceType, Section = new Section { Id = model.SectionId, Code = model.SectionCode }, Date = model.Date, PaymentTerm = model.PaymentTerm, LCNo = model.LCNo, LCDate = model.LCDate, IssuedBy = model.IssuedBy, BuyerAgent = new Buyer { Id = model.BuyerAgentId, Code = model.BuyerAgentCode, Name = model.BuyerAgentName, }, Destination = model.Destination, FinalDestination = model.FinalDestination, ShipmentMode = model.ShipmentMode, TruckingDate = model.TruckingDate, TruckingEstimationDate = model.TruckingEstimationDate, ExportEstimationDate = model.ExportEstimationDate, Omzet = model.Omzet, Accounting = model.Accounting, FabricCountryOrigin = model.FabricCountryOrigin, FabricComposition = model.FabricComposition, RemarkMd = model.RemarkMd, SampleRemarkMd = model.SampleRemarkMd, IsUsed = model.IsUsed, IsPosted = model.IsPosted, IsCostStructured = model.IsCostStructured, IsShipping = model.IsShipping, IsSampleDelivered = model.IsSampleDelivered, IsSampleExpenditureGood = model.IsSampleExpenditureGood, Description = model.Description, Items = (model.Items ?? new List <GarmentPackingListItemModel>()).Select(i => new GarmentPackingListItemViewModel { Active = i.Active, Id = i.Id, CreatedAgent = i.CreatedAgent, CreatedBy = i.CreatedBy, CreatedUtc = i.CreatedUtc, DeletedAgent = i.DeletedAgent, DeletedBy = i.DeletedBy, DeletedUtc = i.DeletedUtc, IsDeleted = i.IsDeleted, LastModifiedAgent = i.LastModifiedAgent, LastModifiedBy = i.LastModifiedBy, LastModifiedUtc = i.LastModifiedUtc, RONo = i.RONo, SCNo = i.SCNo, BuyerBrand = new Buyer { Id = i.BuyerBrandId, Name = i.BuyerBrandName }, Comodity = new Comodity { Id = i.ComodityId, Code = i.ComodityCode, Name = i.ComodityName }, ComodityDescription = i.ComodityDescription, Quantity = i.Quantity, Uom = new UnitOfMeasurement { Id = i.UomId, Unit = i.UomUnit }, PriceRO = i.PriceRO, Price = i.Price, PriceFOB = i.PriceFOB, PriceCMT = i.PriceCMT, Amount = i.Amount, Valas = i.Valas, Unit = new Unit { Id = i.UnitId, Code = i.UnitCode }, Article = i.Article, OrderNo = i.OrderNo, Description = i.Description, DescriptionMd = i.DescriptionMd, RoType = i.RoType, Details = (i.Details ?? new List <GarmentPackingListDetailModel>()).Select(d => new GarmentPackingListDetailViewModel { Active = d.Active, Id = d.Id, CreatedAgent = d.CreatedAgent, CreatedBy = d.CreatedBy, CreatedUtc = d.CreatedUtc, DeletedAgent = d.DeletedAgent, DeletedBy = d.DeletedBy, DeletedUtc = d.DeletedUtc, IsDeleted = d.IsDeleted, LastModifiedAgent = d.LastModifiedAgent, LastModifiedBy = d.LastModifiedBy, LastModifiedUtc = d.LastModifiedUtc, PackingListItemId = d.PackingListItemId, Carton1 = d.Carton1, Carton2 = d.Carton2, Style = d.Style, Colour = d.Colour, CartonQuantity = d.CartonQuantity, QuantityPCS = d.QuantityPCS, TotalQuantity = d.TotalQuantity, Length = d.Length, Width = d.Width, Height = d.Height, GrossWeight = d.GrossWeight, NetWeight = d.NetWeight, NetNetWeight = d.NetNetWeight, Index = d.Index, Sizes = (d.Sizes ?? new List <GarmentPackingListDetailSizeModel>()).Select(s => new GarmentPackingListDetailSizeViewModel { Active = s.Active, Id = s.Id, CreatedAgent = s.CreatedAgent, CreatedBy = s.CreatedBy, CreatedUtc = s.CreatedUtc, DeletedAgent = s.DeletedAgent, DeletedBy = s.DeletedBy, DeletedUtc = s.DeletedUtc, IsDeleted = s.IsDeleted, LastModifiedAgent = s.LastModifiedAgent, LastModifiedBy = s.LastModifiedBy, LastModifiedUtc = s.LastModifiedUtc, Size = new SizeViewModel { Id = s.SizeId, Size = s.Size }, Quantity = s.Quantity }).ToList() }).ToList(), }).ToList(), GrossWeight = model.GrossWeight, NettWeight = model.NettWeight, NetNetWeight = model.NetNetWeight, TotalCartons = model.TotalCartons, Measurements = (model.Measurements ?? new List <GarmentPackingListMeasurementModel>()).GroupBy(g => new { g.Length, g.Width, g.Height }).Select(m => new GarmentPackingListMeasurementViewModel { Active = m.FirstOrDefault().Active, Id = m.FirstOrDefault().Id, CreatedAgent = m.FirstOrDefault().CreatedAgent, CreatedBy = m.FirstOrDefault().CreatedBy, CreatedUtc = m.FirstOrDefault().CreatedUtc, DeletedAgent = m.FirstOrDefault().DeletedAgent, DeletedBy = m.FirstOrDefault().DeletedBy, DeletedUtc = m.FirstOrDefault().DeletedUtc, IsDeleted = m.FirstOrDefault().IsDeleted, LastModifiedAgent = m.FirstOrDefault().LastModifiedAgent, LastModifiedBy = m.FirstOrDefault().LastModifiedBy, LastModifiedUtc = m.FirstOrDefault().LastModifiedUtc, Length = m.FirstOrDefault().Length, Width = m.FirstOrDefault().Width, Height = m.FirstOrDefault().Height, CartonsQuantity = m.Sum(s => s.CartonsQuantity), }).ToList(), SayUnit = model.SayUnit, OtherCommodity = model.OtherCommodity, ShippingMark = model.ShippingMark, SideMark = model.SideMark, Remark = model.Remark, ShippingMarkImagePath = model.ShippingMarkImagePath, SideMarkImagePath = model.SideMarkImagePath, RemarkImagePath = model.RemarkImagePath, ShippingStaff = new ShippingStaff { id = model.ShippingStaffId, name = model.ShippingStaffName, }, Status = model.Status.ToString(), StatusActivities = (model.StatusActivities ?? new List <GarmentPackingListStatusActivityModel>()).Select(a => new GarmentPackingListStatusActivityViewModel { Id = a.Id, CreatedDate = a.CreatedDate, CreatedBy = a.CreatedBy, CreatedAgent = a.CreatedAgent, Status = a.Status.ToString(), Remark = a.Remark }).ToList() }; return(vm); }
public void GetReportData_Success() { var items = new List <GarmentShippingInvoiceItemModel> { new GarmentShippingInvoiceItemModel("2120001", "", 1, "", 12, 1, "", "", "", "comodesc", "comodesc", "comodesc", 1, "PCS", 1, 1, 1, "", 1, "C10", 1, 1) { GarmentShippingInvoiceId = 1 }, new GarmentShippingInvoiceItemModel("2130001", "", 1, "", 21, 1, "", "", "", "comodesc", "comodesc", "comodesc", 2, "SETS", 1, 1, 1, "", 1, "C10", 1, 1) { GarmentShippingInvoiceId = 1 }, new GarmentShippingInvoiceItemModel("2140001", "", 1, "", 31, 2, "", "", "", "comodesc", "comodesc", "comodesc", 1, "PCS", 1, 1, 1, "", 1, "C10", 1, 1) { GarmentShippingInvoiceId = 1 }, }; var model = new GarmentShippingInvoiceModel(1, "DL/210001", DateTimeOffset.Now, "", "", 1, "A99", "", "", "", "", 1, "", "", DateTimeOffset.Now, "", 1, "", 1, "", 1, "", 1, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", "", items, 1, "", "", "", false, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", DateTimeOffset.Now, null, 1, "", "", null) { Id = 1 }; var model1 = new GarmentPackingListModel("DL/210001", "", "DL", 1, "", DateTimeOffset.Now, "", "", DateTimeOffset.Now, "", 1, "", "", "", "", "", DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, false, false, "", "", "", null, 1, 1, 1, 1, null, "", "", "", "", "", "", "", false, false, 1, "", GarmentPackingListStatusEnum.CREATED, "", false, "") { Id = 1 }; var repoMock = new Mock <IGarmentShippingInvoiceRepository>(); repoMock.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingInvoiceModel>() { model }.AsQueryable()); var repoMock1 = new Mock <IGarmentPackingListRepository>(); repoMock1.Setup(s => s.ReadAll()) .Returns(new List <GarmentPackingListModel>() { model1 }.AsQueryable()); var repoMock3 = new Mock <IGarmentShippingInvoiceItemRepository>(); repoMock3.Setup(s => s.ReadAll()) .Returns(items.AsQueryable()); var httpMock = new Mock <IHttpClientService>(); httpMock.Setup(s => s.SendAsync(HttpMethod.Get, It.IsAny <string>(), It.IsAny <HttpContent>())) .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(new { data = new List <GarmentCurrency> { new GarmentCurrency() { code = "usd" } } })) }); httpMock.Setup(s => s.GetAsync(It.IsAny <string>())) .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(new { data = new List <GarmentExpenditureGood> { new GarmentExpenditureGood() { Id = "111", RONo = "2120001", Invoice = "DL/210001", ExpenditureGoodNo = "EGEC10210001", Article = "ART 125214", TotalQuantity = 1250, } } })) }); var spMock = GetServiceProvider(repoMock.Object, repoMock1.Object, repoMock3.Object); spMock.Setup(s => s.GetService(typeof(IHttpClientService))) .Returns(httpMock.Object); var service = GetService(spMock.Object); var result = service.GetReportData(null, DateTime.MinValue, DateTime.MaxValue, 0); Assert.NotEmpty(result.Data); }
public void GetReportData_Success() { var packingListModel = new GarmentPackingListModel("", "", "DL", 1, "", DateTimeOffset.Now, "", "", DateTimeOffset.Now, "", 1, "", "", "", "", "", DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, false, false, "", "", "", null, 1, 1, 1, 1, null, "", "", "", "", "", "", "", false, false, 1, "", GarmentPackingListStatusEnum.CREATED, "", false, "", false, false, false, "") { Id = 1 }; var packingListRepoMock = new Mock <IGarmentPackingListRepository>(); packingListRepoMock.Setup(s => s.ReadAll()) .Returns(new List <GarmentPackingListModel>() { packingListModel }.AsQueryable()); var invoiceItemModels = new HashSet <GarmentShippingInvoiceItemModel> { new GarmentShippingInvoiceItemModel("ro", "scno", 1, "Unitbrandname", 1, 1, "comocode", "comoname", "comodesc", "comodesc", "comodesc", "comodesc", 1, "pcs", 10, 10, 100, "usd", 1, "unitcode", 3, 1) { Id = 1 } }; var invoiceUnitModels = new HashSet <GarmentShippingInvoiceUnitModel> { new GarmentShippingInvoiceUnitModel(1, "unitcode", 3, 1) { Id = 1 } }; var invoiceModel = new GarmentShippingInvoiceModel(1, "invoiceno", DateTimeOffset.Now, "from", "to", 1, "Unitcode", "Unitname", "consignee", "lcno", "issuedby", 1, "sectioncode", "shippingper", DateTimeOffset.Now, "confNo", 1, "staff", 1, "cottn", 1, "mandiri", 10, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", "", invoiceItemModels, 1000, 1000, "23", "dsdsds", "memo", false, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", DateTimeOffset.Now, null, 100000, "aa", "aa", invoiceUnitModels) { Id = 1, PackingListId = packingListModel.Id }; var invoiceRepoMock = new Mock <IGarmentShippingInvoiceRepository>(); invoiceRepoMock.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingInvoiceModel>() { invoiceModel }.AsQueryable()); var httpMock = new Mock <IHttpClientService>(); httpMock.Setup(s => s.GetAsync(It.IsAny <string>())) .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(new { data = new List <Unit> { new Unit() } })) }); var spMock = GetServiceProvider(invoiceRepoMock.Object, packingListRepoMock.Object); spMock.Setup(s => s.GetService(typeof(IHttpClientService))) .Returns(httpMock.Object); var service = GetService(spMock.Object); var result = service.GetReportData(invoiceModel.InvoiceDate.Year); Assert.NotEmpty(result.tables); }
public override Task <int> Update(int id, GarmentPackingListViewModel viewModel) { GarmentPackingListModel model = MapToModel(viewModel); var modelToUpdate = _packingListRepository.Query .Include(i => i.Items) .ThenInclude(i => i.Details) .ThenInclude(i => i.Sizes) .Include(i => i.Measurements) .FirstOrDefault(s => s.Id == id); modelToUpdate.SetSectionId(model.SectionId, _identityProvider.Username, UserAgent); modelToUpdate.SetSectionCode(model.SectionCode, _identityProvider.Username, UserAgent); var measurements = modelToUpdate.Items .SelectMany(i => i.Details.Select(d => new { d.Index, d.Carton1, d.Carton2, d.Length, d.Width, d.Height, d.CartonQuantity, d.CreatedBy })) .GroupBy(m => new { m.Length, m.Width, m.Height, m.CreatedBy }, (k, g) => new GarmentPackingListMeasurementModel(k.Length, k.Width, k.Height, g.Distinct().Sum(d => d.CartonQuantity), k.CreatedBy)); foreach (var itemToUpdate in modelToUpdate.Items.Where(i => i.CreatedBy == _identityProvider.Username)) { var item = model.Items.FirstOrDefault(i => i.Id == itemToUpdate.Id); if (item != null) { itemToUpdate.SetRONo(item.RONo, _identityProvider.Username, UserAgent); itemToUpdate.SetSCNo(item.SCNo, _identityProvider.Username, UserAgent); itemToUpdate.SetBuyerBrandId(item.BuyerBrandId, _identityProvider.Username, UserAgent); itemToUpdate.SetBuyerBrandName(item.BuyerBrandName, _identityProvider.Username, UserAgent); itemToUpdate.SetComodityId(item.ComodityId, _identityProvider.Username, UserAgent); itemToUpdate.SetComodityCode(item.ComodityCode, _identityProvider.Username, UserAgent); itemToUpdate.SetComodityName(item.ComodityName, _identityProvider.Username, UserAgent); itemToUpdate.SetComodityDescription(item.ComodityDescription, _identityProvider.Username, UserAgent); itemToUpdate.SetQuantity(item.Quantity, _identityProvider.Username, UserAgent); itemToUpdate.SetUomId(item.UomId, _identityProvider.Username, UserAgent); itemToUpdate.SetUomUnit(item.UomUnit, _identityProvider.Username, UserAgent); itemToUpdate.SetPriceRO(item.PriceRO, _identityProvider.Username, UserAgent); itemToUpdate.SetPrice(item.Price, _identityProvider.Username, UserAgent); itemToUpdate.SetPriceFob(item.PriceFOB, _identityProvider.Username, UserAgent); itemToUpdate.SetPriceCmt(item.PriceCMT, _identityProvider.Username, UserAgent); itemToUpdate.SetAmount(item.Amount, _identityProvider.Username, UserAgent); itemToUpdate.SetValas(item.Valas, _identityProvider.Username, UserAgent); itemToUpdate.SetUnitId(item.UnitId, _identityProvider.Username, UserAgent); itemToUpdate.SetUnitCode(item.UnitCode, _identityProvider.Username, UserAgent); itemToUpdate.SetArticle(item.Article, _identityProvider.Username, UserAgent); itemToUpdate.SetOrderNo(item.OrderNo, _identityProvider.Username, UserAgent); itemToUpdate.SetDescription(item.Description, _identityProvider.Username, UserAgent); itemToUpdate.SetDescriptionMd(item.DescriptionMd, _identityProvider.Username, UserAgent); itemToUpdate.SetRemarks(item.Remarks, _identityProvider.Username, UserAgent); foreach (var detailToUpdate in itemToUpdate.Details) { var detail = item.Details.FirstOrDefault(d => d.Id == detailToUpdate.Id); if (detail != null) { detailToUpdate.SetCarton1(detail.Carton1, _identityProvider.Username, UserAgent); detailToUpdate.SetCarton2(detail.Carton2, _identityProvider.Username, UserAgent); detailToUpdate.SetStyle(detail.Style, _identityProvider.Username, UserAgent); detailToUpdate.SetColour(detail.Colour, _identityProvider.Username, UserAgent); detailToUpdate.SetCartonQuantity(detail.CartonQuantity, _identityProvider.Username, UserAgent); detailToUpdate.SetQuantityPCS(detail.QuantityPCS, _identityProvider.Username, UserAgent); detailToUpdate.SetTotalQuantity(detail.TotalQuantity, _identityProvider.Username, UserAgent); detailToUpdate.SetLength(detail.Length, _identityProvider.Username, UserAgent); detailToUpdate.SetWidth(detail.Width, _identityProvider.Username, UserAgent); detailToUpdate.SetHeight(detail.Height, _identityProvider.Username, UserAgent); detailToUpdate.SetGrossWeight(detail.GrossWeight, _identityProvider.Username, UserAgent); detailToUpdate.SetNetWeight(detail.NetWeight, _identityProvider.Username, UserAgent); detailToUpdate.SetNetNetWeight(detail.NetNetWeight == 0 ? 0.9 * detail.NetWeight : detail.NetNetWeight, _identityProvider.Username, UserAgent); detailToUpdate.SetIndex(detail.Index, _identityProvider.Username, UserAgent); foreach (var sizeToUpdate in detailToUpdate.Sizes) { var size = detail.Sizes.FirstOrDefault(s => s.Id == sizeToUpdate.Id); if (size != null) { sizeToUpdate.SetSizeId(size.SizeId, _identityProvider.Username, UserAgent); sizeToUpdate.SetSize(size.Size, _identityProvider.Username, UserAgent); sizeToUpdate.SetQuantity(size.Quantity, _identityProvider.Username, UserAgent); } else { sizeToUpdate.FlagForDelete(_identityProvider.Username, UserAgent); } } foreach (var size in detail.Sizes.Where(w => w.Id == 0)) { size.FlagForCreate(_identityProvider.Username, UserAgent); detailToUpdate.Sizes.Add(size); } } else { /*var measurement = model.Measurements.FirstOrDefault(m => m.Length == detailToUpdate.Length && m.Width == detailToUpdate.Width && m.Height == detailToUpdate.Height); * var measurementDB = modelToUpdate.Measurements.FirstOrDefault(m => m.Length == detailToUpdate.Length && m.Width == detailToUpdate.Width && m.Height == detailToUpdate.Height); * foreach(var measurementDb in modelToUpdate.Measurements) * { * * } * if (measurement == null) * { * var sumQty = measurementDB.CartonsQuantity - detailToUpdate.CartonQuantity; * if (sumQty == 0) * { * measurementDB.FlagForDelete(_identityProvider.Username, UserAgent); * } * else * { * measurementDB.SetCartonsQuantity(sumQty, _identityProvider.Username, UserAgent); * } * }*/ detailToUpdate.FlagForDelete(_identityProvider.Username, UserAgent); } } foreach (var detail in item.Details.Where(w => w.Id == 0)) { var netNetWeight = detail.NetNetWeight == 0 ? 0.9 * detail.NetWeight : detail.NetNetWeight; detail.SetNetNetWeight(netNetWeight, _identityProvider.Username, UserAgent); detail.FlagForCreate(_identityProvider.Username, UserAgent); foreach (var size in detail.Sizes) { size.FlagForCreate(_identityProvider.Username, UserAgent); } itemToUpdate.Details.Add(detail); } } else { var items = modelToUpdate.Items.FirstOrDefault(x => x.Id == itemToUpdate.Id); foreach (var detail in items.Details) { var measurement = model.Measurements.FirstOrDefault(m => m.Length == detail.Length && m.Width == detail.Width && m.Height == detail.Height && m.CreatedBy == _identityProvider.Username); var measurementDB = modelToUpdate.Measurements.FirstOrDefault(m => m.Length == detail.Length && m.Width == detail.Width && m.Height == detail.Height && m.CreatedBy == _identityProvider.Username); if (measurement == null) { measurementDB.FlagForDelete(_identityProvider.Username, UserAgent); // harusnya udah kehapus } var detailToDelete = items.Details.FirstOrDefault(d => d.Id == detail.Id); if (detailToDelete != null) { detailToDelete.FlagForDelete(_identityProvider.Username, UserAgent); } } itemToUpdate.FlagForDelete(_identityProvider.Username, UserAgent); } } foreach (var item in model.Items.Where(w => w.Id == 0)) { item.FlagForCreate(_identityProvider.Username, UserAgent); foreach (var detail in item.Details) { detail.SetNetNetWeight(detail.NetNetWeight == 0 ? 0.9 * detail.NetWeight : detail.NetNetWeight, _identityProvider.Username, UserAgent); detail.FlagForCreate(_identityProvider.Username, UserAgent); foreach (var size in detail.Sizes) { size.FlagForCreate(_identityProvider.Username, UserAgent); } } modelToUpdate.Items.Add(item); } foreach (var measurementToUpdate in modelToUpdate.Measurements.Where(m => m.CreatedBy == _identityProvider.Username)) { var measurement = model.Measurements.FirstOrDefault(m => m.Length == measurementToUpdate.Length && m.Width == measurementToUpdate.Width && m.Height == measurementToUpdate.Height && m.CreatedBy == _identityProvider.Username); var measurementDB = measurements.FirstOrDefault(m => m.Length == measurementToUpdate.Length && m.Width == measurementToUpdate.Width && m.Height == measurementToUpdate.Height && m.CreatedBy == _identityProvider.Username); if (measurement != null) { double diffQty = 0; double sumQty = 0; if (measurementDB.CartonsQuantity > measurement.CartonsQuantity) { diffQty = measurementDB.CartonsQuantity - measurement.CartonsQuantity; sumQty = measurementDB.CartonsQuantity - diffQty; } else { diffQty = measurement.CartonsQuantity - measurementDB.CartonsQuantity; sumQty = measurement.CartonsQuantity - diffQty; } measurementToUpdate.SetCartonsQuantity(sumQty, _identityProvider.Username, UserAgent); } else { if (measurementDB != null) { double diffQty = 0; double sumQty = 0; if (measurementDB.CartonsQuantity > measurementToUpdate.CartonsQuantity) { diffQty = measurementDB.CartonsQuantity - measurementToUpdate.CartonsQuantity; sumQty = measurementToUpdate.CartonsQuantity + diffQty; } else { diffQty = measurementToUpdate.CartonsQuantity - measurementDB.CartonsQuantity; sumQty = measurementToUpdate.CartonsQuantity - diffQty; } measurementToUpdate.SetCartonsQuantity(sumQty, _identityProvider.Username, UserAgent); // disini } else { measurementToUpdate.FlagForDelete(_identityProvider.Username, UserAgent); } } /* else * { * measurementToUpdate.FlagForDelete(_identityProvider.Username, UserAgent); * }*/ } foreach (var measurement in measurements.Where(m => m.CreatedBy == _identityProvider.Username)) { var oldMeasurement = modelToUpdate.Measurements.FirstOrDefault(m => m.Length == measurement.Length && m.Width == measurement.Width && m.Height == measurement.Height && m.CreatedBy == _identityProvider.Username); if (oldMeasurement == null) { measurement.FlagForCreate(_identityProvider.Username, UserAgent); modelToUpdate.Measurements.Add(measurement); } /*else * { * double diffQty = 0; * double sumQty = 0; * if (oldMeasurement.CartonsQuantity > measurement.CartonsQuantity) * { * diffQty = oldMeasurement.CartonsQuantity - measurement.CartonsQuantity; * sumQty = oldMeasurement.CartonsQuantity - diffQty; * } * else * { * diffQty = measurement.CartonsQuantity - oldMeasurement.CartonsQuantity; * sumQty = oldMeasurement.CartonsQuantity + diffQty; * } * oldMeasurement.SetCartonsQuantity(sumQty, _identityProvider.Username, UserAgent); * }*/ } var itemsUpdate = modelToUpdate.Items.Where(i => i.IsDeleted == false).OrderBy(o => o.ComodityDescription); var totalCartons = itemsUpdate .SelectMany(i => i.Details.Where(d => d.IsDeleted == false).Select(d => new { d.Index, d.Carton1, d.Carton2, d.CartonQuantity })) .Distinct().Sum(d => d.CartonQuantity); modelToUpdate.SetTotalCartons(totalCartons, _identityProvider.Username, UserAgent); var totalGw = itemsUpdate .SelectMany(i => i.Details.Where(d => d.IsDeleted == false).Select(d => new { d.Index, d.Carton1, d.Carton2, totalGrossWeight = d.CartonQuantity * d.GrossWeight })) .GroupBy(g => new { g.Index, g.Carton1, g.Carton2 }, (key, value) => value.First().totalGrossWeight).Sum(); modelToUpdate.SetGrossWeight(totalGw, _identityProvider.Username, UserAgent); var totalNw = itemsUpdate .SelectMany(i => i.Details.Where(d => d.IsDeleted == false).Select(d => new { d.Index, d.Carton1, d.Carton2, totalNetWeight = d.CartonQuantity * d.NetWeight })) .GroupBy(g => new { g.Index, g.Carton1, g.Carton2 }, (key, value) => value.First().totalNetWeight).Sum(); modelToUpdate.SetNettWeight(totalNw, _identityProvider.Username, UserAgent); var totalNnw = itemsUpdate .SelectMany(i => i.Details.Where(d => d.IsDeleted == false).Select(d => new { d.Index, d.Carton1, d.Carton2, totalNetNetWeight = d.CartonQuantity * d.NetNetWeight })) .GroupBy(g => new { g.Index, g.Carton1, g.Carton2 }, (key, value) => value.First().totalNetNetWeight).Sum(); modelToUpdate.SetNetNetWeight(totalNnw, _identityProvider.Username, UserAgent); return(_packingListRepository.SaveChanges()); }
public void GenerateExcel_Success() { var model = new GarmentPackingListModel("", "", "DL", 1, "", DateTimeOffset.Now, "", "", DateTimeOffset.Now, "", 1, "", "", "", "", "", DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, false, false, "", "", "", null, 1, 1, 1, 1, null, "", "", "", "", "", "", "", false, false, 1, "", GarmentPackingListStatusEnum.CREATED, "") { Id = 1 }; var model1 = new GarmentShippingInvoiceModel(1, "", DateTimeOffset.Now, "", "", 1, "A99", "", "", "", "", 1, "", "", DateTimeOffset.Now, "", 1, "", 1, "", 1, "", 1, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", null, 1, "", "", "", false, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", DateTimeOffset.Now, null, 1, "", "", null) { Id = 1 }; var model2 = new GarmentShippingInstructionModel("no", 1, DateTimeOffset.Now, 1, "", "", "", "", "", "", "", 1, "", "", "", DateTimeOffset.Now, "", "", "", "", "", "", "", "", 1, "", 1, "", "", "", "", "", DateTimeOffset.Now, "", "", "") { Id = 1 }; var model3 = new GarmentShippingCoverLetterModel(1, 1, "", DateTimeOffset.Now, 1, "", "", "", "", "", "", "", DateTimeOffset.Now, 1, "", "", 1, 1, 1, 1, 1, "", "", "", "", "", "", "", "", "", "", DateTimeOffset.Now, "", 1, ""); var model4 = new GarmentShippingCreditAdviceModel(1, 1, "", DateTimeOffset.Now, 1, 1, "", "", true, "", 1, 1, "", DateTimeOffset.Now, DateTimeOffset.Now, "", 1, 1, 1, DateTimeOffset.Now, 1, 1, 1, 1, 1, 1, 1, "", 1, "", "", 1, "", "", 1, 1, 1, DateTimeOffset.Now, "", DateTimeOffset.Now, 1, "", DateTimeOffset.Now, 1, DateTimeOffset.Now, ""); var repoMock1 = new Mock <IGarmentPackingListRepository>(); repoMock1.Setup(s => s.ReadAll()) .Returns(new List <GarmentPackingListModel>() { model }.AsQueryable()); var repoMock2 = new Mock <IGarmentShippingInvoiceRepository>(); repoMock2.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingInvoiceModel>() { model1 }.AsQueryable()); var repoMock3 = new Mock <IGarmentShippingInstructionRepository>(); repoMock3.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingInstructionModel>() { model2 }.AsQueryable()); var repoMock4 = new Mock <IGarmentCoverLetterRepository>(); repoMock4.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingCoverLetterModel>() { model3 }.AsQueryable()); var repoMock5 = new Mock <IGarmentShippingCreditAdviceRepository>(); repoMock5.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingCreditAdviceModel>() { model4 }.AsQueryable()); var service = GetService(GetServiceProvider(repoMock1.Object, repoMock2.Object, repoMock3.Object, repoMock4.Object, repoMock5.Object).Object); var result = service.GenerateExcel(model2.BuyerAgentCode, null, DateTime.MinValue, DateTime.MaxValue, 7); Assert.NotNull(result); }
public override async Task <int> Update(int id, GarmentPackingListViewModel viewModel) { viewModel.ShippingMarkImagePath = await UploadImage(viewModel.ShippingMarkImageFile, viewModel.Id, viewModel.ShippingMarkImagePath, viewModel.CreatedUtc); viewModel.SideMarkImagePath = await UploadImage(viewModel.SideMarkImageFile, viewModel.Id, viewModel.SideMarkImagePath, viewModel.CreatedUtc); viewModel.RemarkImagePath = await UploadImage(viewModel.RemarkImageFile, viewModel.Id, viewModel.RemarkImagePath, viewModel.CreatedUtc); GarmentPackingListModel model = MapToModel(viewModel); GarmentPackingListModel modelToUpdate; if (model.Status == GarmentPackingListStatusEnum.DRAFT_APPROVED_SHIPPING) { modelToUpdate = _packingListRepository.Query .Include(i => i.Items) .ThenInclude(i => i.Details) .Include(i => i.Measurements) .FirstOrDefault(s => s.Id == id); foreach (var itemToUpdate in modelToUpdate.Items) { var item = model.Items.First(i => i.Id == itemToUpdate.Id); foreach (var detailToUpdate in itemToUpdate.Details) { var detail = item.Details.Where(d => d.Id == detailToUpdate.Id).First(); detailToUpdate.SetCarton1(detail.Carton1, _identityProvider.Username, UserAgent); detailToUpdate.SetCarton2(detail.Carton2, _identityProvider.Username, UserAgent); detailToUpdate.SetCartonQuantity(detail.CartonQuantity, _identityProvider.Username, UserAgent); detailToUpdate.SetTotalQuantity(detail.TotalQuantity, _identityProvider.Username, UserAgent); } } foreach (var measurementToUpdate in modelToUpdate.Measurements) { var measurement = model.Measurements.First(m => m.Id == measurementToUpdate.Id); measurementToUpdate.SetCartonsQuantity(measurement.CartonsQuantity, _identityProvider.Username, UserAgent); } } else { modelToUpdate = _packingListRepository.Query.FirstOrDefault(s => s.Id == id); } modelToUpdate.SetDate(model.Date, _identityProvider.Username, UserAgent); modelToUpdate.SetDestination(model.Destination, _identityProvider.Username, UserAgent); modelToUpdate.SetGrossWeight(model.GrossWeight, _identityProvider.Username, UserAgent); modelToUpdate.SetNettWeight(model.NettWeight, _identityProvider.Username, UserAgent); modelToUpdate.SetNetNetWeight(model.NetNetWeight, _identityProvider.Username, UserAgent); modelToUpdate.SetTotalCartons(model.TotalCartons, _identityProvider.Username, UserAgent); modelToUpdate.SetSayUnit(model.SayUnit, _identityProvider.Username, UserAgent); modelToUpdate.SetShippingMark(model.ShippingMark, _identityProvider.Username, UserAgent); modelToUpdate.SetSideMark(model.SideMark, _identityProvider.Username, UserAgent); modelToUpdate.SetRemark(model.Remark, _identityProvider.Username, UserAgent); modelToUpdate.SetShippingMarkImagePath(model.ShippingMarkImagePath, _identityProvider.Username, UserAgent); modelToUpdate.SetSideMarkImagePath(model.SideMarkImagePath, _identityProvider.Username, UserAgent); modelToUpdate.SetRemarkImagePath(model.RemarkImagePath, _identityProvider.Username, UserAgent); modelToUpdate.SetShippingStaff(model.ShippingStaffId, model.ShippingStaffName, _identityProvider.Username, UserAgent); modelToUpdate.SetDescription(model.Description, _identityProvider.Username, UserAgent); return(await _packingListRepository.SaveChanges()); }
public async Task ReadById_Success() { var bills = new HashSet <GarmentShippingPaymentDispositionBillDetailModel> { new GarmentShippingPaymentDispositionBillDetailModel("", 1) { Id = 1 } }; var units = new HashSet <GarmentShippingPaymentDispositionUnitChargeModel> { new GarmentShippingPaymentDispositionUnitChargeModel(1, "", 1, 1) { Id = 1 } }; var invoices = new HashSet <GarmentShippingPaymentDispositionInvoiceDetailModel> { new GarmentShippingPaymentDispositionInvoiceDetailModel("", 1, 1, 1, 1, 1, 1, 1) { Id = 1 } }; var dispoModel = new GarmentShippingPaymentDispositionModel("", "", "", "", "", 1, "", "", "", 1, "", "", 1, "", "", 1, "", "", "", "", "", DateTimeOffset.Now, "", 1, 1, 1, "", 1, 1, 1, DateTimeOffset.Now, "", "", true, "", "", DateTimeOffset.Now, "", "", "", invoices, bills, units) { Id = 1 }; var item = new GarmentShippingPaymentDispositionRecapItemModel(1, 10, 10, 10, 10, 10) { Id = 1 }; item.SetPaymentDisposition(dispoModel); var items = new HashSet <GarmentShippingPaymentDispositionRecapItemModel> { item }; var model = new GarmentShippingPaymentDispositionRecapModel("", DateTimeOffset.Now, 1, "", "", "", "", items) { Id = 1 }; var repoMock = new Mock <IGarmentShippingPaymentDispositionRecapRepository>(); repoMock.Setup(s => s.ReadByIdAsync(It.IsAny <int>())) .ReturnsAsync(model); var dispoRepoMock = new Mock <IGarmentShippingPaymentDispositionRepository>(); dispoRepoMock.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingPaymentDispositionModel> { dispoModel }.AsQueryable()); var itemsInvoice = new HashSet <GarmentShippingInvoiceItemModel> { new GarmentShippingInvoiceItemModel("ro", "scno", 1, "buyerbrandname", 1, 1, "comocode", "comoname", "comodesc", "comodesc", "comodesc", "comodesc", 1, "pcs", 10, 10, 100, "usd", 1, "unitcode", 3, 1) { Id = 1 } }; var adjustmentsInvoice = new HashSet <GarmentShippingInvoiceAdjustmentModel> { new GarmentShippingInvoiceAdjustmentModel(1, "fee", 100, 1) { Id = 1 } }; var unitsInvoice = new HashSet <GarmentShippingInvoiceUnitModel> { new GarmentShippingInvoiceUnitModel(1, "unitcode", 3, 1) { Id = 1 } }; var invoiceModel = new GarmentShippingInvoiceModel(1, "invoiceno", DateTimeOffset.Now, "from", "to", 1, "buyercode", "buyername", "consignee", "lcno", "issuedby", 1, "sectioncode", "shippingper", DateTimeOffset.Now, "confNo", 1, "staff", 1, "cottn", 1, "mandiri", 10, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", "", itemsInvoice, 1000, "dddd", "dsdsds", "memo", false, "", DateTimeOffset.Now, "", DateTimeOffset.Now, "", DateTimeOffset.Now, adjustmentsInvoice, 100000, "aa", "aa", unitsInvoice) { Id = 1 }; var invoiceRepoMock = new Mock <IGarmentShippingInvoiceRepository>(); invoiceRepoMock.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingInvoiceModel> { invoiceModel }.AsQueryable()); var measurements = new HashSet <GarmentPackingListMeasurementModel> { new GarmentPackingListMeasurementModel(1, 1, 1, 1) { Id = 1 } }; var packingListModel = new GarmentPackingListModel("", "", "", 1, "", DateTimeOffset.Now, "", "", DateTimeOffset.Now, "", 1, "", "", "", "", "", DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, false, false, "", "", "", null, 1, 1, 1, 1, measurements, "", "", "", "", "", "", "", false, false, 1, "", GarmentPackingListStatusEnum.CREATED, "", false, "") { Id = 1 }; var packingListRepoMock = new Mock <IGarmentPackingListRepository>(); packingListRepoMock.Setup(s => s.ReadAll()) .Returns(new List <GarmentPackingListModel> { packingListModel }.AsQueryable()); var spMock = GetServiceProvider(repoMock.Object); spMock.Setup(s => s.GetService(typeof(IGarmentShippingPaymentDispositionRepository))) .Returns(dispoRepoMock.Object); spMock.Setup(s => s.GetService(typeof(IGarmentShippingInvoiceRepository))) .Returns(invoiceRepoMock.Object); spMock.Setup(s => s.GetService(typeof(IGarmentPackingListRepository))) .Returns(packingListRepoMock.Object); var service = GetService(spMock.Object); var result = await service.ReadById(1); Assert.NotNull(result); }
public Task <int> UpdateAsync(int id, GarmentPackingListModel model) { var modelToUpdate = _dbSet .Include(i => i.Items) .ThenInclude(i => i.Details) .ThenInclude(i => i.Sizes) .Include(i => i.Measurements) .FirstOrDefault(s => s.Id == id); modelToUpdate.SetPackingListType(model.PackingListType, _identityProvider.Username, UserAgent); modelToUpdate.SetSectionId(model.SectionId, _identityProvider.Username, UserAgent); modelToUpdate.SetSectionCode(model.SectionCode, _identityProvider.Username, UserAgent); modelToUpdate.SetDate(model.Date, _identityProvider.Username, UserAgent); modelToUpdate.SetPaymentTerm(model.PaymentTerm, _identityProvider.Username, UserAgent); modelToUpdate.SetLCNo(model.LCNo, _identityProvider.Username, UserAgent); modelToUpdate.SetLCDate(model.LCDate, _identityProvider.Username, UserAgent); modelToUpdate.SetIssuedBy(model.IssuedBy, _identityProvider.Username, UserAgent); modelToUpdate.SetBuyerAgentId(model.BuyerAgentId, _identityProvider.Username, UserAgent); modelToUpdate.SetBuyerAgentCode(model.BuyerAgentCode, _identityProvider.Username, UserAgent); modelToUpdate.SetBuyerAgentName(model.BuyerAgentName, _identityProvider.Username, UserAgent); modelToUpdate.SetDestination(model.Destination, _identityProvider.Username, UserAgent); modelToUpdate.SetFinalDestination(model.FinalDestination, _identityProvider.Username, UserAgent); modelToUpdate.SetShipmentMode(model.ShipmentMode, _identityProvider.Username, UserAgent); modelToUpdate.SetTruckingDate(model.TruckingDate, _identityProvider.Username, UserAgent); modelToUpdate.SetTruckingEstimationDate(model.TruckingEstimationDate, _identityProvider.Username, UserAgent); modelToUpdate.SetExportEstimationDate(model.ExportEstimationDate, _identityProvider.Username, UserAgent); modelToUpdate.SetFabricCountryOrigin(model.FabricCountryOrigin, _identityProvider.Username, UserAgent); modelToUpdate.SetFabricComposition(model.FabricComposition, _identityProvider.Username, UserAgent); modelToUpdate.SetOmzet(model.Omzet, _identityProvider.Username, UserAgent); modelToUpdate.SetAccounting(model.Accounting, _identityProvider.Username, UserAgent); modelToUpdate.SetRemarkMd(model.RemarkMd, _identityProvider.Username, UserAgent); modelToUpdate.SetGrossWeight(model.GrossWeight, _identityProvider.Username, UserAgent); modelToUpdate.SetNettWeight(model.NettWeight, _identityProvider.Username, UserAgent); modelToUpdate.SetNetNetWeight(model.NetNetWeight, _identityProvider.Username, UserAgent); modelToUpdate.SetTotalCartons(model.TotalCartons, _identityProvider.Username, UserAgent); modelToUpdate.SetSayUnit(model.SayUnit, _identityProvider.Username, UserAgent); modelToUpdate.SetShippingMark(model.ShippingMark, _identityProvider.Username, UserAgent); modelToUpdate.SetSideMark(model.SideMark, _identityProvider.Username, UserAgent); modelToUpdate.SetRemark(model.Remark, _identityProvider.Username, UserAgent); modelToUpdate.SetShippingMarkImagePath(model.ShippingMarkImagePath, _identityProvider.Username, UserAgent); modelToUpdate.SetSideMarkImagePath(model.SideMarkImagePath, _identityProvider.Username, UserAgent); modelToUpdate.SetRemarkImagePath(model.RemarkImagePath, _identityProvider.Username, UserAgent); modelToUpdate.SetShippingStaff(model.ShippingStaffId, model.ShippingStaffName, _identityProvider.Username, UserAgent); modelToUpdate.SetStatus(model.Status, _identityProvider.Username, UserAgent); foreach (var itemToUpdate in modelToUpdate.Items) { var item = model.Items.FirstOrDefault(i => i.Id == itemToUpdate.Id); if (item != null) { itemToUpdate.SetRONo(item.RONo, _identityProvider.Username, UserAgent); itemToUpdate.SetSCNo(item.SCNo, _identityProvider.Username, UserAgent); itemToUpdate.SetBuyerBrandId(item.BuyerBrandId, _identityProvider.Username, UserAgent); itemToUpdate.SetBuyerBrandName(item.BuyerBrandName, _identityProvider.Username, UserAgent); itemToUpdate.SetComodityId(item.ComodityId, _identityProvider.Username, UserAgent); itemToUpdate.SetComodityCode(item.ComodityCode, _identityProvider.Username, UserAgent); itemToUpdate.SetComodityName(item.ComodityName, _identityProvider.Username, UserAgent); itemToUpdate.SetComodityDescription(item.ComodityDescription, _identityProvider.Username, UserAgent); itemToUpdate.SetQuantity(item.Quantity, _identityProvider.Username, UserAgent); itemToUpdate.SetUomId(item.UomId, _identityProvider.Username, UserAgent); itemToUpdate.SetUomUnit(item.UomUnit, _identityProvider.Username, UserAgent); itemToUpdate.SetPriceRO(item.PriceRO, _identityProvider.Username, UserAgent); itemToUpdate.SetPrice(item.Price, _identityProvider.Username, UserAgent); itemToUpdate.SetPriceFob(item.PriceFOB, _identityProvider.Username, UserAgent); itemToUpdate.SetPriceCmt(item.PriceCMT, _identityProvider.Username, UserAgent); itemToUpdate.SetAmount(item.Amount, _identityProvider.Username, UserAgent); itemToUpdate.SetValas(item.Valas, _identityProvider.Username, UserAgent); itemToUpdate.SetUnitId(item.UnitId, _identityProvider.Username, UserAgent); itemToUpdate.SetUnitCode(item.UnitCode, _identityProvider.Username, UserAgent); itemToUpdate.SetArticle(item.Article, _identityProvider.Username, UserAgent); itemToUpdate.SetOrderNo(item.OrderNo, _identityProvider.Username, UserAgent); itemToUpdate.SetDescription(item.Description, _identityProvider.Username, UserAgent); itemToUpdate.SetDescriptionMd(item.DescriptionMd, _identityProvider.Username, UserAgent); foreach (var detailToUpdate in itemToUpdate.Details) { var detail = item.Details.FirstOrDefault(d => d.Id == detailToUpdate.Id); if (detail != null) { detailToUpdate.SetCarton1(detail.Carton1, _identityProvider.Username, UserAgent); detailToUpdate.SetCarton2(detail.Carton2, _identityProvider.Username, UserAgent); detailToUpdate.SetColour(detail.Colour, _identityProvider.Username, UserAgent); detailToUpdate.SetCartonQuantity(detail.CartonQuantity, _identityProvider.Username, UserAgent); detailToUpdate.SetQuantityPCS(detail.QuantityPCS, _identityProvider.Username, UserAgent); detailToUpdate.SetTotalQuantity(detail.TotalQuantity, _identityProvider.Username, UserAgent); detailToUpdate.SetLength(detail.Length, _identityProvider.Username, UserAgent); detailToUpdate.SetWidth(detail.Width, _identityProvider.Username, UserAgent); detailToUpdate.SetHeight(detail.Height, _identityProvider.Username, UserAgent); detailToUpdate.SetGrossWeight(detail.GrossWeight, _identityProvider.Username, UserAgent); detailToUpdate.SetNetWeight(detail.NetWeight, _identityProvider.Username, UserAgent); detailToUpdate.SetNetNetWeight(detail.NetNetWeight, _identityProvider.Username, UserAgent); foreach (var sizeToUpdate in detailToUpdate.Sizes) { var size = detail.Sizes.FirstOrDefault(s => s.Id == sizeToUpdate.Id); if (size != null) { sizeToUpdate.SetSizeId(size.SizeId, _identityProvider.Username, UserAgent); sizeToUpdate.SetSize(size.Size, _identityProvider.Username, UserAgent); sizeToUpdate.SetQuantity(size.Quantity, _identityProvider.Username, UserAgent); } else { sizeToUpdate.FlagForDelete(_identityProvider.Username, UserAgent); } } foreach (var size in detail.Sizes.Where(w => w.Id == 0)) { size.FlagForCreate(_identityProvider.Username, UserAgent); detailToUpdate.Sizes.Add(size); } } else { detailToUpdate.FlagForDelete(_identityProvider.Username, UserAgent); } } foreach (var detail in item.Details.Where(w => w.Id == 0)) { detail.FlagForCreate(_identityProvider.Username, UserAgent); foreach (var size in detail.Sizes) { size.FlagForCreate(_identityProvider.Username, UserAgent); } itemToUpdate.Details.Add(detail); } } else { itemToUpdate.FlagForDelete(_identityProvider.Username, UserAgent); } } foreach (var item in model.Items.Where(w => w.Id == 0)) { item.FlagForCreate(_identityProvider.Username, UserAgent); foreach (var detail in item.Details) { detail.FlagForCreate(_identityProvider.Username, UserAgent); foreach (var size in detail.Sizes) { size.FlagForCreate(_identityProvider.Username, UserAgent); } } modelToUpdate.Items.Add(item); } foreach (var measurementToUpdate in modelToUpdate.Measurements) { var measurement = model.Measurements.FirstOrDefault(m => m.Id == measurementToUpdate.Id); if (measurement != null) { measurementToUpdate.SetLength(measurement.Length, _identityProvider.Username, UserAgent); measurementToUpdate.SetWidth(measurement.Width, _identityProvider.Username, UserAgent); measurementToUpdate.SetHeight(measurement.Height, _identityProvider.Username, UserAgent); measurementToUpdate.SetCartonsQuantity(measurement.CartonsQuantity, _identityProvider.Username, UserAgent); } else { measurementToUpdate.FlagForDelete(_identityProvider.Username, UserAgent); } } foreach (var measurement in model.Measurements.Where(w => w.Id == 0)) { measurement.FlagForCreate(_identityProvider.Username, UserAgent); modelToUpdate.Measurements.Add(measurement); } return(_dbContext.SaveChangesAsync()); }