PurchaseOrderSplitViewModel createModel(int id, bool bLock = false) { var model = new PurchaseOrderSplitViewModel(); PrepareViewModel(model, EvolutionResources.bnrSplitPurchase, id); model.ParentId = id; model.OrderDetails.PurchaseOrderHeaderId = id; var poh = PurchasingService.FindPurchaseOrderHeaderModel(id, CurrentCompany); if (poh != null) { model.OrderDetails.SupplierName = poh.SupplierName; model.OrderDetails.OrderNumber = poh.OrderNumber.Value; if (poh.RequiredDate != null) { model.OrderDetails.AdvertisedETA = poh.RequiredDate.Value.ToString(model.DisplayDateFormat); } if (bLock) { model.LGS = PurchasingService.LockPurchaseOrderHeader(poh); } } model.OrderDetails.NewOrderAdvertisedETA = DateTimeOffset.Now; model.LocationList = LookupService.FindLocationListItemModel(CurrentCompany, true); model.PurchaseOrderList = PurchasingService.FindPurchaseOrderHeadersString(CurrentCompany, true); return(model); }
public void FindShipmentContentByPONoModelTest() { var testUser = GetTestUser(); var testCompany = GetTestCompany(testUser, true); var testShipment = GetTestShipment(testCompany, testUser, 10); var newPoh = GetTestPurchaseOrderHeader(testCompany, testUser, RandomInt(10, 20)); var newItem = ShipmentService.AddPurchaseOrder(testCompany, testUser, testShipment, newPoh); var checkContent = ShipmentService.FindShipmentContentByPONoModel(testCompany, newPoh.OrderNumber.Value, false); Assert.IsTrue(checkContent != null, "Error: A NULL value was returned when an object was expected"); var checkPoh = PurchasingService.FindPurchaseOrderHeaderModel(checkContent.PurchaseOrderHeaderId.Value, testCompany, false); var excludes = new List <string>(); excludes.Add("OrderNumberUrl"); // Because it isn't known at test prep AreEqual(newPoh, checkPoh, excludes); db.DeletePurchaseOrderHeader(newPoh.Id); // Check that it has gone checkContent = ShipmentService.FindShipmentContentByPONoModel(testCompany, newPoh.OrderNumber.Value, false); Assert.IsTrue(checkContent == null, "Error: A non-NULL value was returned when a NULL value was expected"); checkPoh = PurchasingService.FindPurchaseOrderHeaderModel(newPoh.Id, testCompany, false); Assert.IsTrue(checkPoh == null, "Error: An object was returned when NULL was expected"); }
public void FindPurchaseOrderHeaderModelTest() { var testUser = GetTestUser(); var testCompany = GetTestCompany(testUser, true); var model = GetTestPurchaseOrderHeader(testCompany, testUser); var test = PurchasingService.FindPurchaseOrderHeaderModel(model.Id, testCompany, false); var excludes = new List <string>(); excludes.Add("OrderNumberUrl"); // Because it isn't known in data prep AreEqual(model, test, excludes); }
public ActionResult Edit(int id) { // Called when a user clicks to edit an order var model = new EditPurchaseOrderHeaderTempViewModel(); var purchase = PurchasingService.FindPurchaseOrderHeaderModel(id, CurrentCompany, true); // Copy the order into temp tables for editing model.PurchaseTemp = PurchasingService.CopyPurchaseOrderToTemp(CurrentCompany, purchase, CurrentUser); prepareEditModel(model, model.PurchaseTemp.Id); model.LGS = PurchasingService.LockPurchaseOrderHeader(purchase); model.LGST = PurchasingService.LockPurchaseOrderHeaderTemp(model.PurchaseTemp); return(View("Edit", model)); }
public ActionResult Add() { // Called when the user clicks 'Create' to create a new order var editModel = new EditPurchaseOrderHeaderTempViewModel(); var purchase = PurchasingService.FindPurchaseOrderHeaderModel(0, CurrentCompany, true); purchase.OrderDate = DateTimeOffset.Now; purchase.SalespersonId = CurrentUser.Id; purchase.BrandCategoryId = CurrentUser.DefaultBrandCategoryId; purchase.LocationId = CurrentCompany.DefaultLocationID; purchase.CancelMessage = CurrentCompany.CancelMessage; // Copy the order into temp tables for editing editModel.PurchaseTemp = PurchasingService.CopyPurchaseOrderToTemp(CurrentCompany, purchase, CurrentUser); return(EditDetails(editModel.PurchaseTemp.Id)); }
public ActionResult EditDetails(int id) { // Called when a user is on one of the order screens and clicks the order details option var model = new EditPurchaseOrderHeaderTempViewModel(); // Use the data in the temp tables var purchaseTemp = PurchasingService.FindPurchaseOrderHeaderTempModel(id, CurrentCompany, true); purchaseTemp.UserId = CurrentUser.Id; model.PurchaseTemp = purchaseTemp; prepareEditModel(model, id); var purchase = PurchasingService.FindPurchaseOrderHeaderModel(purchaseTemp.OriginalRowId, CurrentCompany, true); model.LGS = PurchasingService.LockPurchaseOrderHeader(purchase); model.LGST = PurchasingService.LockPurchaseOrderHeaderTemp(model.PurchaseTemp); return(View("Edit", model)); }
public void SplitToExistingOrderTest() { var testUser = GetTestUser(); var testCompany = GetTestCompany(testUser, true); var sourceOrder = GetTestPurchaseOrderHeader(testCompany, testUser, 4); var sourceOrderItems = PurchasingService.FindPurchaseOrderDetailListModel(sourceOrder); // Create a model to split an item off to a new order SplitPurchaseModel model = new SplitPurchaseModel { PurchaseOrderHeaderId = sourceOrder.Id, SupplierName = "", OrderNumber = 0, AdvertisedETA = null, NewOrderAdvertisedETA = DateTimeOffset.Now.AddDays(20), LocationId = 0 }; // Try to split off more items than the original order var existingOrder = GetTestPurchaseOrderHeader(testCompany, testUser, 0); var splitItem = createSplitItemModel(sourceOrderItems.Items[0].Id, 0, 1500, existingOrder.Id, 1); model.SplitItems.Add(splitItem); int updatedPOId = 0, newPOId = 0; var lgs = PurchasingService.LockPurchaseOrderHeader(sourceOrder); var error = PurchasingService.SplitOrder(testCompany, model, testUser, lgs, ref updatedPOId, ref newPOId); Assert.IsTrue(error.IsError, "$Error: An error was expected but none was returned"); // Try to split off to an invalid 'existing' order splitItem = createSplitItemModel(sourceOrderItems.Items[0].Id, 0, 5, -1, 1); model.SplitItems.Clear(); model.SplitItems.Add(splitItem); error = PurchasingService.SplitOrder(testCompany, model, testUser, lgs, ref updatedPOId, ref newPOId); Assert.IsTrue(error.IsError, "$Error: An error was expected but none was returned"); // Now try to split a valid number of items off to an existing order int originalQty = sourceOrderItems.Items[0].OrderQty.Value, splitQty = 10; splitItem = createSplitItemModel(sourceOrderItems.Items[0].Id, 0, splitQty, existingOrder.Id, 1); model.SplitItems.Clear(); model.SplitItems.Add(splitItem); lgs = PurchasingService.LockPurchaseOrderHeader(sourceOrder); error = PurchasingService.SplitOrder(testCompany, model, testUser, lgs, ref updatedPOId, ref newPOId); Assert.IsTrue(!error.IsError, error.Message); // Check the newly created copy of the original record we have split var updatedOrder = PurchasingService.FindPurchaseOrderHeaderModel(updatedPOId, testCompany, false); Assert.IsTrue(updatedOrder != null, "Error: A NULL value was returned when an object was expected"); var updatedPohd = PurchasingService.FindPurchaseOrderDetailListModel(updatedOrder); int expected = originalQty - splitQty, actual = updatedPohd.Items[0].OrderQty.Value; Assert.IsTrue(actual == expected, $"Error: The order quantity is now {actual} when {expected} was expected"); // .. and that the updated order has a note with PDF attachment var noteList = NoteService.FindNotesListModel(NoteType.Purchase, updatedPOId, 0, 1, 1000, "", MediaSize.Medium, 0, 0); expected = 1; actual = noteList.Items.Count(); Assert.IsTrue(actual == expected, $"Error: (1) Order was found to have {actual} notes when {expected} were expected"); var noteAttachments = NoteService.FindNoteAttachmentsModel(noteList.Items[0], MediaSize.Medium, 0, 0); expected = 1; actual = noteAttachments.Count(); Assert.IsTrue(actual == expected, $"Error: (1) Order note was found to have {actual} attachment PDFs when {expected} were expected"); // Look for the new record in the exiting order var newPohdList = db.FindPurchaseOrderDetails(testCompany.Id, existingOrder.Id) .OrderByDescending(ni => ni.Id) .ToList(); Assert.IsTrue(newPohdList.Count() == 1, $"Error: {newPohdList.Count()} items were returned when 1 was expected"); expected = splitQty; actual = newPohdList[0].OrderQty.Value; Assert.IsTrue(actual == splitQty, $"Error: {actual} items were returned when {expected} was expected"); // .. and that the existing order has a note with PDF attachment noteList = NoteService.FindNotesListModel(NoteType.Purchase, existingOrder.Id, 0, 1, 1000, "", MediaSize.Medium, 0, 0); expected = 1; actual = noteList.Items.Count(); Assert.IsTrue(actual == expected, $"Error: (2) Order was found to have {actual} notes when {expected} were expected"); noteAttachments = NoteService.FindNoteAttachmentsModel(noteList.Items[0], MediaSize.Medium, 0, 0); expected = 1; actual = noteAttachments.Count(); Assert.IsTrue(actual == expected, $"Error: (2) Order note was found to have {actual} attachment PDFs when {expected} were expected"); // TBD: Check that the allocations have been modified }