private void mapItem(PurchaseOrderLineItem item, PurchaseOrderLineItem input) { item.QuantityOrdered = input.QuantityOrdered; item.SizeOfUnit = input.SizeOfUnit; item.UnitType = input.UnitType; item.Price = input.Price; }
private List <PurchaseOrderLineItem> GetPurchaseOrderLineItemsFromShopifyOrder(Order order) { // generate the list of purchase order elements var purchaseOrderLineItems = new List <PurchaseOrderLineItem>(); foreach (LineItem lineItem in order.LineItems) { var purchaseOrderLineItem = new PurchaseOrderLineItem(); purchaseOrderLineItem.ID = (lineItem.Id.HasValue ? lineItem.Id.Value : 0); purchaseOrderLineItem.OrderID = order.Name; purchaseOrderLineItem.SKU = string.Format("{0} ({1})", lineItem.SKU, lineItem.VariantTitle); purchaseOrderLineItem.Quantity = (lineItem.Quantity.HasValue ? lineItem.Quantity.Value : 0); // get agreed usd price var priceUSD = GetLineItemAgreedPriceUSD(lineItem); purchaseOrderLineItem.PriceUSD = priceUSD; //string.Format(new CultureInfo("en-US", false), "{0:C}", priceUSD); purchaseOrderLineItem.Name = Utils.GetNormalizedEquivalentPhrase(order.Customer.FirstName + " " + order.Customer.LastName); purchaseOrderLineItem.Address1 = Utils.GetNormalizedEquivalentPhrase(order.Customer.DefaultAddress.Address1); purchaseOrderLineItem.City = Utils.GetNormalizedEquivalentPhrase(order.Customer.DefaultAddress.City); purchaseOrderLineItem.Country = Utils.GetNormalizedEquivalentPhrase(order.Customer.DefaultAddress.Country); purchaseOrderLineItem.ZipCode = order.Customer.DefaultAddress.Zip; purchaseOrderLineItem.Telephone = appConfig["PurchaseOrderTelephone"]; purchaseOrderLineItem.Remarks = appConfig["PurchaseOrderRemarks"]; // Utils.GetNormalizedEquivalentPhrase(order.Note); purchaseOrderLineItem.BuyerName = appConfig["PurchaseOrderBuyerName"]; purchaseOrderLineItem.BuyerEmail = appConfig["PurchaseOrderBuyerEmail"]; purchaseOrderLineItems.Add(purchaseOrderLineItem); } return(purchaseOrderLineItems); }
public ActionResult SaveItem(PurchaseOrderLineItemViewModel input) { var vendor = _repository.Find <Vendor>(input.RootId); var currentUser = _sessionContext.GetCurrentUser(); var purchaseOrder = input.ParentId > 0 ? vendor.GetPurchaseOrderInProcess().FirstOrDefault(x => x.EntityId == input.ParentId) : new PurchaseOrder { Vendor = vendor, Status = TemporalStatus.Pending.ToString() }; var baseProduct = _repository.Find <BaseProduct>(input.PurchaseOrderLineItem.Product.EntityId); var newPo = purchaseOrder.EntityId == 0; var purchaseOrderLineItem = new PurchaseOrderLineItem { Product = baseProduct, PurchaseOrder = purchaseOrder }; mapItem(purchaseOrderLineItem, input.PurchaseOrderLineItem); purchaseOrder.AddLineItem(purchaseOrderLineItem); if (purchaseOrder.EntityId == 0) { vendor.AddPurchaseOrder(purchaseOrder); } var crudManager = _saveEntityService.ProcessSave(purchaseOrder); var notification = crudManager.Finish(); notification.Data = new { poId = purchaseOrder.EntityId }; if (newPo) { notification.Redirect = true; notification.RedirectUrl = UrlContext.GetUrlForAction <PurchaseOrderController>(x => x.AddEdit(null)) + "/" + vendor.EntityId + "?ParentId=" + purchaseOrder.EntityId; } return(Json(notification, JsonRequestBehavior.AllowGet)); }
public JsonResult Save(PurchaseOrderLineItem record, long id) { // try to get the line item list from the session List <PurchaseOrderLineItem> purchaseOrderLineItems = null; if ((purchaseOrderLineItems = HttpContext.Session.Get <List <PurchaseOrderLineItem> >(SessionKeyPurchaseOrderLineItems)) == null) { // if not found, look it up var order = DataFactory.GetShopifyOrder(appConfig, id); purchaseOrderLineItems = GetPurchaseOrderLineItemsFromShopifyOrder(order); } PurchaseOrderLineItem entity; if (record.ID > 0) { entity = purchaseOrderLineItems.First(p => p.ID == record.ID); entity.OrderID = record.OrderID; entity.SKU = record.SKU; entity.Quantity = record.Quantity; entity.PriceUSD = record.PriceUSD; entity.Name = record.Name; entity.Address1 = record.Address1; entity.City = record.City; entity.Country = record.Country; entity.ZipCode = record.ZipCode; entity.Telephone = record.Telephone; entity.Remarks = record.Remarks; } else { // Add a new PurchaseOrderLineItem purchaseOrderLineItems.Add(new PurchaseOrderLineItem { OrderID = record.OrderID, SKU = record.SKU, Quantity = record.Quantity, PriceUSD = record.PriceUSD, Name = record.Name, Address1 = record.Address1, City = record.City, Country = record.Country, ZipCode = record.ZipCode, Telephone = record.Telephone, Remarks = record.Remarks }); } // and store it in the session HttpContext.Session.Set <List <PurchaseOrderLineItem> >(SessionKeyPurchaseOrderLineItems, purchaseOrderLineItems); return(Json(new { result = true })); }
public void Setup() { _poliId = 0; _repo = MockRepository.GenerateMock <IRepository>(); _purchaseOrderLineItem = ObjectMother.ValidPurchaseOrderLineItem("raif"); _inventoryBaseProducts = new List <InventoryProduct>().AsQueryable(); _purchaseOrderLineItem.TotalReceived = 4; _repo.Expect(x => x.Query <InventoryProduct>(null)).IgnoreArguments().Return(_inventoryBaseProducts); _crudManager = MockRepository.GenerateMock <ICrudManager>(); _crudManager.Expect(x => x.Finish()).Return(new Notification()); _saveEntityService = MockRepository.GenerateMock <ISaveEntityService>(); _sesCatcher = _saveEntityService.CaptureArgumentsFor(x => x.ProcessSave(_inventoryBaseProducts.FirstOrDefault(), null), x => x.Return(_crudManager)); _SUT = new InventoryService(_repo, _saveEntityService); _crudManager = _SUT.ReceivePurchaseOrderLineItem(_purchaseOrderLineItem); }
public ICrudManager ReceivePurchaseOrderLineItem(PurchaseOrderLineItem purchaseOrderLineItem, ICrudManager crudManager = null) { var inventoryProducts = _repository.Query <InventoryProduct>(x => x.Product.EntityId == purchaseOrderLineItem.Product.EntityId && x.UnitType == purchaseOrderLineItem.UnitType); var inventoryProduct = inventoryProducts.FirstOrDefault() ?? new InventoryProduct { Product = purchaseOrderLineItem.Product, UnitType = purchaseOrderLineItem.UnitType, SizeOfUnit = purchaseOrderLineItem.SizeOfUnit }; inventoryProduct.LastVendor = purchaseOrderLineItem.PurchaseOrder.Vendor; inventoryProduct.Quantity += purchaseOrderLineItem.TotalReceived.Value; return(_saveEntityService.ProcessSave(inventoryProduct, crudManager)); }
public void Setup() { _poliId = 0; _repo = MockRepository.GenerateMock<IRepository>(); _purchaseOrderLineItem = ObjectMother.ValidPurchaseOrderLineItem("raif"); _inventoryBaseProducts = new List<InventoryProduct> { ObjectMother.ValidInventoryBaseProduct("raif")}.AsQueryable(); _purchaseOrderLineItem.TotalReceived = 4; _repo.Expect(x => x.Query<InventoryProduct>(null)).IgnoreArguments().Return(_inventoryBaseProducts); _saveEntityService = MockRepository.GenerateMock<ISaveEntityService>(); _crudManager = MockRepository.GenerateMock<ICrudManager>(); _crudManager.Expect(x => x.Finish()).Return(new Notification()); _sesCatcher = _saveEntityService.CaptureArgumentsFor(x=>x.ProcessSave(_inventoryBaseProducts.FirstOrDefault(),null),x=>x.Return(_crudManager)); _SUT = new InventoryService(_repo, _saveEntityService); _crudManager = _SUT.ReceivePurchaseOrderLineItem(_purchaseOrderLineItem); }
public JsonResult Delete(long id) { // try to get the line item list from the session List <PurchaseOrderLineItem> purchaseOrderLineItems = null; if ((purchaseOrderLineItems = HttpContext.Session.Get <List <PurchaseOrderLineItem> >(SessionKeyPurchaseOrderLineItems)) == null) { // if not found, look it up var order = DataFactory.GetShopifyOrder(appConfig, id); purchaseOrderLineItems = GetPurchaseOrderLineItemsFromShopifyOrder(order); } PurchaseOrderLineItem entity = purchaseOrderLineItems.First(p => p.ID == id); purchaseOrderLineItems.Remove(entity); // and store it in the session HttpContext.Session.Set <List <PurchaseOrderLineItem> >(SessionKeyPurchaseOrderLineItems, purchaseOrderLineItems); return(Json(new { result = true })); }
public ActionResult AddItem(ViewModel input) { var vendor = _repository.Find <Vendor>(input.RootId); var currentUser = _sessionContext.GetCurrentUser(); var purchaseOrder = input.ParentId > 0 ? vendor.GetPurchaseOrderInProcess().FirstOrDefault(x => x.EntityId == input.ParentId) : new PurchaseOrder { Vendor = vendor }; var baseProduct = _repository.Find <BaseProduct>(input.EntityId); var purchaseOrderLineItem = new PurchaseOrderLineItem { Product = baseProduct, PurchaseOrder = purchaseOrder }; var model = new PurchaseOrderLineItemViewModel { PurchaseOrderLineItem = purchaseOrderLineItem }; return(View(model)); }
private void CreateVendor() { _vendor1 = new Vendor { Company = "Some Company1", Phone = "555.123.4567", Fax = "123.456.7891", Website = "www.somewebsite1.com", LogoUrl = "someurl1", Notes = "notes1" }; _vendor2 = new Vendor { Company = "Some Company2", Phone = "555.123.4567", Fax = "123.456.7891", Website = "www.somewebsite2.com", LogoUrl = "someurl2", Notes = "notes2" }; _vendor1.AddProduct(_fertilizer1); _vendor1.AddProduct(_fertilizer2); _vendor2.AddProduct(_fertilizer1); _vendor2.AddProduct(_fertilizer2); _vendor1.AddProduct(_chemical1); _vendor1.AddProduct(_chemical2); _vendor2.AddProduct(_chemical1); _vendor2.AddProduct(_chemical2); _vendor1.AddProduct(_materials1); _vendor1.AddProduct(_materials2); _vendor2.AddProduct(_materials1); _vendor2.AddProduct(_materials2); _vendor1.AddProduct(_seed1); _vendor1.AddProduct(_seed2); _vendor2.AddProduct(_seed1); _vendor2.AddProduct(_seed2); _repository.Save(_vendor1); _repository.Save(_vendor2); var purchaseOrder1 = new PurchaseOrder { Vendor = _vendor1, DateCreated = DateTime.Parse("1/5/2009"), Status = TemporalStatus.Complete.Key }; var poli1 = new PurchaseOrderLineItem() { Product = _fertilizer1, Price = 10, QuantityOrdered = 5, Tax = 5 }; var poli2 = new PurchaseOrderLineItem() { Product = _fertilizer1, Price = 10, QuantityOrdered = 5, Tax = 5 }; var poli3 = new PurchaseOrderLineItem() { Product = _materials1, Price = 10, QuantityOrdered = 5, Tax = 5 }; var poli4 = new PurchaseOrderLineItem() { Product = _materials2, Price = 10, QuantityOrdered = 5, Tax = 5 }; var poli5 = new PurchaseOrderLineItem() { Product = _chemical2, Price = 10, QuantityOrdered = 5, Tax = 5 }; var poli6 = new PurchaseOrderLineItem() { Product = _chemical1, Price = 10, QuantityOrdered = 5, Tax = 5 }; purchaseOrder1.AddLineItem(poli1); purchaseOrder1.AddLineItem(poli2); purchaseOrder1.AddLineItem(poli3); purchaseOrder1.AddLineItem(poli4); purchaseOrder1.AddLineItem(poli5); purchaseOrder1.AddLineItem(poli6); _vendor1.AddPurchaseOrder(purchaseOrder1); _repository.Save(_vendor1); }
private void CreateVendor() { _vendor1 = new Vendor { Company = "Some Company1", Phone = "555.123.4567", Fax = "123.456.7891", Website = "www.somewebsite1.com", LogoUrl = "someurl1", Notes = "notes1" }; _vendor2 = new Vendor { Company = "Some Company2", Phone = "555.123.4567", Fax = "123.456.7891", Website = "www.somewebsite2.com", LogoUrl = "someurl2", Notes = "notes2" }; _vendor1.AddProduct(_fertilizer1); _vendor1.AddProduct(_fertilizer2); _vendor2.AddProduct(_fertilizer1); _vendor2.AddProduct(_fertilizer2); _vendor1.AddProduct(_chemical1); _vendor1.AddProduct(_chemical2); _vendor2.AddProduct(_chemical1); _vendor2.AddProduct(_chemical2); _vendor1.AddProduct(_materials1); _vendor1.AddProduct(_materials2); _vendor2.AddProduct(_materials1); _vendor2.AddProduct(_materials2); _vendor1.AddProduct(_seed1); _vendor1.AddProduct(_seed2); _vendor2.AddProduct(_seed1); _vendor2.AddProduct(_seed2); _repository.Save(_vendor1); _repository.Save(_vendor2); var purchaseOrder1 = new PurchaseOrder {Vendor = _vendor1, DateCreated = DateTime.Parse("1/5/2009"), Status = TemporalStatus.Complete.Key}; var poli1 = new PurchaseOrderLineItem() { Product = _fertilizer1, Price = 10, QuantityOrdered = 5, Tax = 5 }; var poli2 = new PurchaseOrderLineItem() { Product = _fertilizer1, Price = 10, QuantityOrdered = 5, Tax = 5 }; var poli3 = new PurchaseOrderLineItem() { Product = _materials1, Price = 10, QuantityOrdered = 5, Tax = 5 }; var poli4 = new PurchaseOrderLineItem() { Product = _materials2, Price = 10, QuantityOrdered = 5, Tax = 5 }; var poli5 = new PurchaseOrderLineItem() { Product = _chemical2, Price = 10, QuantityOrdered = 5, Tax = 5 }; var poli6 = new PurchaseOrderLineItem() { Product = _chemical1, Price = 10, QuantityOrdered = 5, Tax = 5 }; purchaseOrder1.AddLineItem(poli1); purchaseOrder1.AddLineItem(poli2); purchaseOrder1.AddLineItem(poli3); purchaseOrder1.AddLineItem(poli4); purchaseOrder1.AddLineItem(poli5); purchaseOrder1.AddLineItem(poli6); _vendor1.AddPurchaseOrder(purchaseOrder1); _repository.Save(_vendor1); }