private Error recreatePurchaseOrderPdfs(SplitPurchaseModel model, CompanyModel company, UserModel user, PurchaseOrderHeaderModel updatedOrder, PurchaseOrderHeaderModel newOrder) { var error = new Error(); // Recreate purchase order PDFs // Newly created order (if any) if (newOrder != null) { error = createRevisedPurchaseOrder(newOrder.Id, company, user, "Purchase Order Created with items moved from Order " + model.OrderNumber.ToString()); } // New Source order (Order split from) error = createRevisedPurchaseOrder(updatedOrder.Id, company, user, "Purchase Order Updated (due to items split out)"); // Orders split to foreach (var targetOrderId in model.SplitItems .Where(si => si.TargetOrderId > 0) .Select(si => si.TargetOrderId) .Distinct()) { error = createRevisedPurchaseOrder(targetOrderId, company, user, "Purchase Order Updated - items moved from Order " + model.OrderNumber.ToString()); if (error.IsError) { break; } } return(error); }
public ModelError SendCompletedPurchaseOrderToAccounts(PurchaseOrderHeaderModel poh) { ModelError error = new ModelError(); error.SetInfo(EvolutionResources.infOrderCompleted); return(error); }
public PurchaseOrderHeaderModel FindPurchaseOrderHeaderModel(int id, CompanyModel company, bool bCreateEmptyIfNotfound = true) { PurchaseOrderHeaderModel model = null; var p = db.FindPurchaseOrderHeader(id); if (p == null) { if (bCreateEmptyIfNotfound) { model = new PurchaseOrderHeaderModel { CompanyId = company.Id, OrderNumber = LookupService.GetNextSequenceNumber(company, SequenceNumberType.PurchaseOrderNumber) } } ; } else { model = MapToModel(p); } return(model); }
Error sendUnpackSlipMessage(PurchaseOrderHeaderModel poh, CompanyModel company, // Company of the file transfer NoteModel note, int poNumber, List <UserModel> userList) { Dictionary <string, string> dict = new Dictionary <string, string>(); dict.AddProperty("PURCHASEORDERNO", poNumber); dict.AddProperty("COMPANYNAME", company.FriendlyName); UserModel purchaser = MembershipManagementService.FindUserModel(poh.SalespersonId.Value); dict.AddProperty("PURCHASER", (purchaser == null ? "" : (purchaser.FirstName + " " + purchaser.LastName).Trim())); dict.AddProperty("SUPPLIER", poh.SupplierName); var attachment = NoteService.FindNoteAttachmentsModel(note, MediaSize.Medium, 0, 0).FirstOrDefault(); string url = ""; if (attachment != null) { url = MediaService.GetMediaFileName(attachment.Media, true); } dict.AddProperty("URL", url); return(SendMessage(company, user, MessageTemplateType.UnpackSlipNotification, TaskType.Default, userList, dict)); }
private Error validateModel(PurchaseOrderHeaderModel model) { var error = isValidNonRequiredString(getFieldValue(model.SupplierInv), 255, "SupplierInv", EvolutionResources.errTextDataRequiredInField); if (!error.IsError) { error = isValidNonRequiredString(getFieldValue(model.ShipAddress1), 255, "ShipAddress1", EvolutionResources.errTextDataRequiredInField); } if (!error.IsError) { error = isValidNonRequiredString(getFieldValue(model.ShipAddress2), 255, "ShipAddress2", EvolutionResources.errTextDataRequiredInField); } if (!error.IsError) { error = isValidNonRequiredString(getFieldValue(model.ShipAddress3), 255, "ShipAddress3", EvolutionResources.errTextDataRequiredInField); } if (!error.IsError) { error = isValidNonRequiredString(getFieldValue(model.ShipAddress4), 255, "ShipAddress4", EvolutionResources.errTextDataRequiredInField); } if (!error.IsError) { error = isValidNonRequiredString(getFieldValue(model.OrderComment), 255, "OrderComment", EvolutionResources.errTextDataRequiredInField); } if (!error.IsError) { error = isValidNonRequiredString(getFieldValue(model.CancelMessage), 2048, "CancelMessage", EvolutionResources.errTextDataRequiredInField); } if (!error.IsError) { error = isValidNonRequiredString(getFieldValue(model.OrderConfirmationNo), 20, "OrderConfirmationNo", EvolutionResources.errTextDataRequiredInField); } return(error); }
public ShipmentContentModel AddPurchaseOrder(CompanyModel company, UserModel user, ShipmentModel shipment, PurchaseOrderHeaderModel poh) { ShipmentContentModel newItem = null; var shipmentContent = FindShipmentContentListModel(company, shipment.Id, 0); if (shipmentContent.Items .Where(sc => sc.PurchaseOrderHeaderId == poh.Id) .Count() == 0) { // Not already on the shipment, so add it Supplier supplier = null; if (poh.SupplierId != null) { supplier = db.FindSupplier(poh.SupplierId.Value); } var content = new ShipmentContentModel { CompanyId = company.Id, ShipmentId = shipment.Id, PurchaseOrderHeaderId = poh.Id, OrderNumber = poh.OrderNumber, // Was PONo CBMEstimate = db.FindPurchaseOrderCBMs(poh.Id), //public double? CBMCharged { set; get; } = 0; SupplierId = poh.SupplierId, SupplierName = (supplier == null ? "" : supplier.Name), //public string ProductBrand { set; get; } = ""; }; InsertOrUpdateShipmentContent(content, user, ""); newItem = content; } return(newItem); }
public List <UserModel> FindOrderPurchasers(PurchaseOrderHeaderModel poh, CompanyModel company, decimal poNumber, ref string errorMsg) { // Given a PurchaseOrderHeader model, finds the sales person (purchaser) // for the order and returns a list of all the users in the same user // group as the sales person, including the sales person. List <UserModel> users = null; UserModel salesPerson = null; if (poh.SalespersonId != null) { salesPerson = MembershipManagementService.FindUserModel(poh.SalespersonId.Value); } if (salesPerson != null) { // Found the sales person BrandCategoryModel brandCat = null; if (poh.BrandCategoryId != null) { brandCat = ProductService.FindBrandCategoryModel(poh.BrandCategoryId.Value, company, false); } if (brandCat != null) { string groupName = brandCat.CategoryName.ToLower() + " purchasing"; var userGroup = MembershipManagementService.FindGroupsForUser(salesPerson) .Where(ug => ug.GroupName.ToLower().Contains(groupName)) .FirstOrDefault(); if (userGroup != null) { // Found the group, so get all the users in the group, including the sales person users = MembershipManagementService.FindUsersInGroup(userGroup); if (users.Count() == 0) { errorMsg = $"Error: Active Directory User Group '{groupName}' has no members!"; users = null;; } } else { errorMsg = $"Error: Failed to find Active Directory Group '{groupName}' !"; } } else { errorMsg = $"Error: Failed to find a Brand Catgeory for Purchase Order Number {poNumber} !"; } } else { errorMsg = $"Error: Failed to find a Sales Person for Purchase Order Number {poNumber} !"; } return(users); }
public decimal FindPurchaseOrderTotal(PurchaseOrderHeaderModel poh) { decimal rc = 0; foreach (var pod in FindPurchaseOrderDetailListModel(poh).Items) { rc += pod.UnitPriceExTax.Value * (decimal)pod.OrderQty.Value; } return(rc); }
public Error ImportOrders(CompanyModel company, UserModel user, int locationId, List <string> headings) { var error = new Error(); int lastSupplierId = -1, lineNo = 0; PurchaseOrderHeaderModel poh = null; // Create an order for each supplier foreach (var row in db.FindFileImportRows(company.Id, user.Id) .Skip(1) // Skip first record (headers) .OrderBy(r => r.Product.Supplier.Name) .ToList()) { if (row.SupplierId != lastSupplierId) { // Found another supplier, so start a new order poh = new PurchaseOrderHeaderModel { CompanyId = company.Id, SupplierId = row.SupplierId, OrderNumber = LookupService.GetNextSequenceNumber(company, SequenceNumberType.PurchaseOrderNumber), OrderDate = DateTimeOffset.Now, POStatus = LookupService.FindPurchaseOrderHeaderStatusByValueModel(PurchaseOrderStatus.OrderPlanned).Id, SalespersonId = user.Id, LocationId = locationId, CurrencyId = row.Product.Supplier.CurrencyId, ExchangeRate = LookupService.FindCurrencyModel(row.Product.Supplier.CurrencyId.Value).ExchangeRate.Value }; InsertOrUpdatePurchaseOrderHeader(poh, user, ""); lastSupplierId = row.SupplierId.Value; lineNo = 1000; } // Add items to the new order var pod = new PurchaseOrderDetailModel { CompanyId = company.Id, PurchaseOrderHeaderId = poh.Id, LineNumber = lineNo, ProductId = row.ProductId, ProductDescription = row.Product.ItemName, UnitPriceExTax = Convert.ToDecimal(getField(row, "UnitPrice").Value), TaxCodeId = row.Product.Supplier.TaxCodeId.Value, OrderQty = Convert.ToInt32(getField(row, "Quantity").Value) }; InsertOrUpdatePurchaseOrderDetail(pod, user, ""); lineNo += 1000; } return(error); }
// The following method is called by the Purchasing Service when a Purchase Order is saved // It could also be called manually by the user for allocation optimisation public void AllocateOnPurchaseOrderSave(PurchaseOrderHeaderModel poh) { var pohStatus = db.FindPurchaseOrderHeaderStatus(poh.POStatus); if (pohStatus != null && pohStatus.AllowAllocation) { // The status of the purchase allows an allocation // Only adjust allocations on products in the order } }
// The following method is called from the Purchasing service when a Purchase Order is being split public void AllocateOnPurchaseOrderSplit(PurchaseOrderDetailModel pod, // Line we split from List <AllocationModel> allocList, // Allocations linked to the line (ordered by DateCreated) PurchaseOrderHeaderModel targetPo, // PO we are splitting to (the 'later' PO)) PurchaseOrderDetailModel targetPod, // Line we are spliting to int numSplitItems, // Number of items being split UserModel user) { // On entry, the allocList must be in DateCreated order // Every allocation will always have a purchase order line Id and a sales order line Id // Update the purchase order detail pod.OrderQty -= numSplitItems; if (allocList.Count > 0) { // Is window open of the allocation greater than or equal to the // the ReallisticETA of the PO were are spliting to ? var sod = db.FindSalesOrderDetail(allocList[0].SaleLineId.Value); if (sod.SalesOrderHeader.DeliveryWindowOpen != null && targetPo.RealisticRequiredDate != null) { // Only do something if the window and required date are set if (sod.SalesOrderHeader.DeliveryWindowOpen >= targetPo.RealisticRequiredDate) { // Yes, Is there free stock on the later PO ? if (getFreeStock(targetPod, allocList) >= numSplitItems) { // Yes, assign allocation to later PO allocList[0].PurchaseLineId = targetPod.Id; } else { // No, assign allocation to earlier PO allocList[0].PurchaseLineId = pod.Id; } } else { // No, is there free stock on the earlier PO ? if (getFreeStock(pod, allocList) >= numSplitItems) { // Yes, assign allocation to earlier PO allocList[0].PurchaseLineId = pod.Id; } else { // No, assign allocation to later PO allocList[0].PurchaseLineId = targetPod.Id; } } InsertOrUpdateAllocation(allocList[0], user, LockAllocation(allocList[0])); } } }
public AllocationListModel FindAllocationsToPurchaseOrder(PurchaseOrderHeaderModel poh) { AllocationListModel model = new AllocationListModel(); foreach (var item in db.FindAllocationsToPurchaseOrder(poh.Id) .OrderBy(a => a.PurchaseLineId) .ThenBy(a => a.DateCreated)) { var alloc = MapToModel(item); model.Items.Add(alloc); } return(model); }
public PurchaseOrderDetailListModel FindPurchaseOrderDetailListModel(PurchaseOrderHeaderModel poh) { var model = new PurchaseOrderDetailListModel(); var allItems = db.FindPurchaseOrderDetails(poh.CompanyId, poh.Id); model.TotalRecords = allItems.Count(); foreach (var item in allItems) { var orderLine = MapToModel(item); model.Items.Add(orderLine); } return(model); }
private Error copyOrder(CompanyModel company, SplitPurchaseModel model, UserModel user) { var error = new Error(); var updatedOrderNo = LookupService.GetNextSequenceNumber(company, SequenceNumberType.PurchaseOrderNumber, origPoh.OrderNumber.Value, true); var newPohId = db.CopyPurchaseOrder(model.PurchaseOrderHeaderId, updatedOrderNo, true).First().Value; updatedPoh = FindPurchaseOrderHeaderModel(newPohId, company, false); updatedDetails = FindPurchaseOrderDetailListModel(updatedPoh); updatedAllocations = AllocationService.FindAllocationsToPurchaseOrder(updatedPoh).Items; return(error); }
private string createUnpackListFile(PurchaseOrderHeaderModel poh) { string fileName = GetTempFile(".csv"); using (StreamWriter sw = new StreamWriter(fileName)) { sw.WriteLine("PO_NUMBER,LINE_NR,PART_NUMBER,QTY_RECEIVED,UOM,VARIANCE"); sw.WriteLine(poh.OrderNumber.ToString() + ",1,ABC,24,EACH,0"); sw.WriteLine(poh.OrderNumber.ToString() + ",2, ABC, 36, EACH, 0"); sw.WriteLine(poh.OrderNumber.ToString() + ",3, ABC, 36, EACH, 0"); sw.WriteLine(poh.OrderNumber.ToString() + ",4, ABC, 24, EACH, 0"); sw.WriteLine(poh.OrderNumber.ToString() + ",5, ABC, 24, EACH, 0"); sw.WriteLine(poh.OrderNumber.ToString() + ",6, ABC, 200, EACH, 0"); } return(fileName); }
public PurchaseOrderHeaderModel FindPurchaseOrderHeaderByPONumberModel(decimal poNumber, CompanyModel company) { PurchaseOrderHeaderModel model = null; var p = db.FindPurchaseOrderHeaders(company.Id) .Where(poh => poh.OrderNumber == poNumber) .FirstOrDefault(); if (p != null) { model = MapToModel(p); } return(model); }
public void GetNextSequenceNumberTest() { var user = GetTestUser(); var testCompany = GetTestCompany(user); decimal actual = 0; // At this stage, no sequences or orders exist for (int expected = 1; expected <= 10; expected++) { actual = LookupService.GetNextSequenceNumber(testCompany, SequenceNumberType.PurchaseOrderNumber); Assert.IsTrue(actual == expected, $"Error: {actual} was returned when {expected} was expected"); } // Find the "Warehouse" location var location = db.FindLocations() .Where(l => l.LocationName == "Warehouse") .FirstOrDefault(); // Find a supplier with lots of products var supplier = db.FindSuppliers(testCompany.Id) .Where(s => s.Products.Count() > 100) .FirstOrDefault(); // Now create a purchase order with a large purchase order number var poh = new PurchaseOrderHeaderModel { CompanyId = testCompany.Id, LocationId = location.Id, POStatus = Convert.ToInt32(LookupService.FindPurchaseOrderHeaderStatusListItemModel().First().Id), SupplierId = supplier.Id, SupplierInv = "INV" + RandomInt(1000, 9999).ToString(), RequiredDate = RandomDateTime(), OrderNumber = 1000 }; var error = PurchasingService.InsertOrUpdatePurchaseOrderHeader(poh, user, ""); Assert.IsTrue(!error.IsError, error.Message); // Check that the correct number is returned // On the first iteration, the next number should be one more than the largest purchase order number ie 1001 for (int expected = 1001; expected <= 1010; expected++) { actual = LookupService.GetNextSequenceNumber(testCompany, SequenceNumberType.PurchaseOrderNumber); Assert.IsTrue(actual == expected, $"Error: {actual} was returned when {expected} was expected"); } }
public PurchaseOrderHeaderModel MapToModel(PurchaseOrderHeader item) { PurchaseOrderHeaderModel newItem = null; if (item != null) { newItem = Mapper.Map <PurchaseOrderHeader, PurchaseOrderHeaderModel>(item); string poNumber = item.OrderNumber.ToString(); if (poNumber.IndexOf(".") != -1) { poNumber = poNumber.TrimEnd('0').TrimEnd('.'); } newItem.OrderNumberUrl = $"<a href=\"/Purchasing/EditPurchase/Edit?id={item.Id}\">{poNumber}</a>"; if (item.Supplier != null) { newItem.SupplierName = item.Supplier.Name; } if (item.PurchaseOrderHeaderStatu != null) { newItem.POStatusText = item.PurchaseOrderHeaderStatu.StatusName; newItem.POStatusValue = (PurchaseOrderStatus)item.PurchaseOrderHeaderStatu.StatusValue; } newItem.SalesPersonName = db.MakeName(item.User_SalesPerson); newItem.Splitable = item.PurchaseOrderDetails.Count > 0; // Landing date if (newItem.OrderNumber != null) { var company = CompanyService.FindCompanyModel(newItem.CompanyId); var shipmentContent = item.ShipmentContents.FirstOrDefault(); // ShipmentService.FindShipmentContentByPONoModel(company, newItem.OrderNumber.Value); if (shipmentContent != null && shipmentContent.ShipmentId != null) { var shipment = ShipmentService.FindShipmentModel(shipmentContent.ShipmentId.Value, company); newItem.LandingDate = shipment.DatePreAlertETA; } } } return(newItem); }
bool createNoteWithAttachment(PurchaseOrderHeaderModel poh, CompanyModel company, string fileName, ref NoteModel note, ref string errorMsg) { bool bError = false; note = new NoteModel { CompanyId = company.Id, NoteType = NoteType.Purchase, ParentId = poh.Id, DateCreated = DateTimeOffset.Now, CreatedById = user.Id, Subject = "Unpack Slip - Order " + poh.OrderNumber.ToString(), Message = "" }; var error = NoteService.InsertOrUpdateNote(note, user, ""); if (error.IsError) { errorMsg = error.Message; bError = true; } else { // Move the file to the purchase order note attachment folder for the // specific purchase order error = NoteService.AttachMediaItemToNote(note, user, fileName, fileName.FileName(), FileCopyType.Move); if (error.IsError) { errorMsg = error.Message; bError = true; } } return(bError); }
PurchaseOrderHeaderModel mapToModel(PurchaseOrderHeaderModel item) { return(Mapper.Map <PurchaseOrderHeaderModel, PurchaseOrderHeaderModel>(item)); }
public Error CreatePurchaseOrderPdf(PurchaseOrderHeaderModel poh, int?templateId, string pdfFile, ref string outputFile) { return(CreatePurchaseOrderPdf(db.FindPurchaseOrderHeader(poh.Id), templateId ?? 0, pdfFile, ref outputFile)); }
public void IntegrationTest() { var connection = TestSession.GetConnection(); connection.Open(); #region good insertion and select by id test PurchaseOrderHeaderModel inserted = new PurchaseOrderHeaderModel(); inserted.RevisionNumber = Convert.ToByte(TestSession.Random.RandomString(3)); inserted.Status = Convert.ToByte(TestSession.Random.RandomString(3)); inserted.EmployeeID = TestSession.Random.Next(); inserted.VendorID = TestSession.Random.Next(); inserted.ShipMethodID = TestSession.Random.Next(); inserted.OrderDate = TestSession.Random.RandomDateTime(); inserted.ShipDate = TestSession.Random.RandomDateTime(); inserted.SubTotal = TestSession.Random.RandomDecimal(); inserted.TaxAmt = TestSession.Random.RandomDecimal(); inserted.Freight = TestSession.Random.RandomDecimal(); inserted.TotalDue = TestSession.Random.RandomDecimal(); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Insert(connection, new[] { inserted }); var selectedAfterInsertion = _tested.GetByPrimaryKey(connection, new PurchaseOrderHeaderModelPrimaryKey() { PurchaseOrderID = inserted.PurchaseOrderID, }); CollectionAssert.IsNotEmpty(selectedAfterInsertion); var selectedAfterInsert = selectedAfterInsertion.Single(); Assert.AreEqual(inserted.PurchaseOrderID, selectedAfterInsert.PurchaseOrderID); Assert.AreEqual(inserted.RevisionNumber, selectedAfterInsert.RevisionNumber); Assert.AreEqual(inserted.Status, selectedAfterInsert.Status); Assert.AreEqual(inserted.EmployeeID, selectedAfterInsert.EmployeeID); Assert.AreEqual(inserted.VendorID, selectedAfterInsert.VendorID); Assert.AreEqual(inserted.ShipMethodID, selectedAfterInsert.ShipMethodID); Assert.AreEqual(inserted.OrderDate, selectedAfterInsert.OrderDate); Assert.AreEqual(inserted.ShipDate, selectedAfterInsert.ShipDate); Assert.AreEqual(inserted.SubTotal, selectedAfterInsert.SubTotal); Assert.AreEqual(inserted.TaxAmt, selectedAfterInsert.TaxAmt); Assert.AreEqual(inserted.Freight, selectedAfterInsert.Freight); Assert.AreEqual(inserted.TotalDue, selectedAfterInsert.TotalDue); Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate); #endregion #region update and select by id test inserted.RevisionNumber = Convert.ToByte(TestSession.Random.RandomString(3)); inserted.Status = Convert.ToByte(TestSession.Random.RandomString(3)); inserted.EmployeeID = TestSession.Random.Next(); inserted.VendorID = TestSession.Random.Next(); inserted.ShipMethodID = TestSession.Random.Next(); inserted.OrderDate = TestSession.Random.RandomDateTime(); inserted.ShipDate = TestSession.Random.RandomDateTime(); inserted.SubTotal = TestSession.Random.RandomDecimal(); inserted.TaxAmt = TestSession.Random.RandomDecimal(); inserted.Freight = TestSession.Random.RandomDecimal(); inserted.TotalDue = TestSession.Random.RandomDecimal(); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Update(connection, new[] { inserted }); var selectedAfterUpdateAddresss = _tested.GetByPrimaryKey(connection, new PurchaseOrderHeaderModelPrimaryKey() { PurchaseOrderID = inserted.PurchaseOrderID, }); CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss); var selectedAfterUpdate = selectedAfterUpdateAddresss.Single(); Assert.AreEqual(inserted.PurchaseOrderID, selectedAfterUpdate.PurchaseOrderID); Assert.AreEqual(inserted.RevisionNumber, selectedAfterUpdate.RevisionNumber); Assert.AreEqual(inserted.Status, selectedAfterUpdate.Status); Assert.AreEqual(inserted.EmployeeID, selectedAfterUpdate.EmployeeID); Assert.AreEqual(inserted.VendorID, selectedAfterUpdate.VendorID); Assert.AreEqual(inserted.ShipMethodID, selectedAfterUpdate.ShipMethodID); Assert.AreEqual(inserted.OrderDate, selectedAfterUpdate.OrderDate); Assert.AreEqual(inserted.ShipDate, selectedAfterUpdate.ShipDate); Assert.AreEqual(inserted.SubTotal, selectedAfterUpdate.SubTotal); Assert.AreEqual(inserted.TaxAmt, selectedAfterUpdate.TaxAmt); Assert.AreEqual(inserted.Freight, selectedAfterUpdate.Freight); Assert.AreEqual(inserted.TotalDue, selectedAfterUpdate.TotalDue); Assert.AreEqual(inserted.ModifiedDate, selectedAfterUpdate.ModifiedDate); #endregion #region delete test _tested.Delete(connection, new[] { inserted }); var selectedAfterDeleteAddresss = _tested.GetByPrimaryKey(connection, new PurchaseOrderHeaderModelPrimaryKey() { PurchaseOrderID = inserted.PurchaseOrderID, }); CollectionAssert.IsEmpty(selectedAfterDeleteAddresss); #endregion connection.Close(); }
public string LockPurchaseOrderHeader(PurchaseOrderHeaderModel model) { return(db.LockRecord(typeof(PurchaseOrderHeader).ToString(), model.Id)); }
public void DeletePurchaseOrderHeader(PurchaseOrderHeaderModel model) { db.DeletePurchaseOrderHeader(model.Id); }
public Error InsertOrUpdatePurchaseOrderHeader(PurchaseOrderHeaderModel poh, UserModel user, string lockGuid) { var error = validateModel(poh); if (!error.IsError) { // Check that the lock is still current if (!db.IsLockStillValid(typeof(PurchaseOrderHeader).ToString(), poh.Id, lockGuid)) { error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "OrderNumber"); } else { PurchaseOrderHeader temp = null; if (poh.Id != 0) { temp = db.FindPurchaseOrderHeader(poh.Id); } if (temp == null) { temp = new PurchaseOrderHeader(); } var before = Mapper.Map <PurchaseOrderHeader, PurchaseOrderHeader>(temp); Mapper.Map <PurchaseOrderHeaderModel, PurchaseOrderHeader>(poh, temp); // So objects are linked temp.Company = db.FindCompany(poh.CompanyId); db.InsertOrUpdatePurchaseOrderHeader(temp); poh.Id = temp.Id; logChanges(before, temp, user); // If shanges have occured, we need to send an email to any sales person // who has allocations reliant on the order if (before.POStatus != temp.POStatus && temp.POStatus == (int)PurchaseOrderStatus.Cancelled) { // Order has been cancelled, so send a cancellation notification to everyone /* * public int POStatus { set; get; } = 0; // Cancelled * public DateTimeOffset? CancelDate { set; get; } = null; * */ } else { // Check the dates and email everyone of the changes /* * public DateTimeOffset? RequiredDate { set; get; } * public DateTimeOffset? CompletedDate { set; get; } * * public DateTimeOffset? RequiredShipDate { set; get; } = null; // SRD Final * public DateTimeOffset? RealisticRequiredDate { set; get; } = null; // Reallistic ETA * * public DateTimeOffset? RequiredDate_Original { set; get; } = null; * public DateTimeOffset? DateOrderConfirmed { set; get; } = null; * public DateTimeOffset? RequiredShipDate_Original { set; get; } = null; // SRD Initial */ } } } return(error); }
public PurchaseOrderHeaderTempModel CopyPurchaseOrderToTemp(CompanyModel company, PurchaseOrderHeaderModel purchaseOrderHeader, UserModel user) { PurchaseOrderHeaderTempModel result = new PurchaseOrderHeaderTempModel(); PurchaseOrderHeaderTemp poht = new PurchaseOrderHeaderTemp(); // Clean the temp tables if (purchaseOrderHeader.Id > 0) { // Editing an existing order var poh = db.FindPurchaseOrderHeader(purchaseOrderHeader.Id); if (poh != null) { // Copy the header poht = db.FindPurchaseOrderHeaderTemps(company.Id) .Where(p => p.UserId == user.Id && p.OriginalRowId == purchaseOrderHeader.Id) .FirstOrDefault(); if (poht != null) { // Already exists in the temp tables so update it with the latest data int tempId = poht.Id; Mapper.Map <PurchaseOrderHeader, PurchaseOrderHeaderTemp>(poh, poht); poht.Id = tempId; poht.OriginalRowId = purchaseOrderHeader.Id; poht.UserId = user.Id; db.InsertOrUpdatePurchaseOrderHeaderTemp(poht); result = mapToModel(poht); } else { // Doesn't exist, so copy poht = Mapper.Map <PurchaseOrderHeader, PurchaseOrderHeaderTemp>(poh); poht.Id = 0; poht.OriginalRowId = purchaseOrderHeader.Id; poht.UserId = user.Id; db.InsertOrUpdatePurchaseOrderHeaderTemp(poht); result = mapToModel(poht); } // Now copy/merge the details db.CopyPurchaseOrderToTemp(company.Id, user.Id, purchaseOrderHeader.Id, poht.Id); result.Splitable = db.FindPurchaseOrderDetailTemps(company.Id, poht.Id).Count() > 0; } } else { // New purchase poht.CompanyId = company.Id; poht.UserId = user.Id; poht.OrderNumber = purchaseOrderHeader.OrderNumber; poht.OrderDate = purchaseOrderHeader.OrderDate; poht.SalespersonId = purchaseOrderHeader.SalespersonId; poht.BrandCategoryId = purchaseOrderHeader.BrandCategoryId; poht.LocationId = purchaseOrderHeader.LocationId; poht.CancelMessage = purchaseOrderHeader.CancelMessage; db.InsertOrUpdatePurchaseOrderHeaderTemp(poht); result = mapToModel(poht); } return(result); }
private Error validateSplit(CompanyModel company, SplitPurchaseModel model, UserModel user, string lockGuid) { var error = new Error(); // Check that the lock is still current because we are about to change it by // moving detail lines from it if (!db.IsLockStillValid(typeof(PurchaseOrderHeader).ToString(), model.PurchaseOrderHeaderId, lockGuid)) { error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "NewOrderAdvertisedETA"); } else { podList = new List <PurchaseOrderDetailModel>(); numItems = 0; origPoh = FindPurchaseOrderHeaderModel(model.PurchaseOrderHeaderId, company, false); foreach (var splitItem in model.SplitItems) { // Count the items to be split/moved numItems += splitItem.NewOrderQty + splitItem.TargetOrderQty; // Get the items on the order var pod = FindPurchaseOrderDetailModel(splitItem.PurchaseOrderDetailId); if (pod == null) { error.SetRecordError("PurchaseOrderDetail", splitItem.PurchaseOrderDetailId); break; } else if (splitItem.NewOrderQty + splitItem.TargetOrderQty > pod.OrderQty) { if (splitItem.NewOrderQty > 0) { error.SetError(EvolutionResources.errCantSplitMoreThanOriginalQty, $"txtSplitToNewOrderQty{splitItem.RowNumber}_4_0"); } else { error.SetError(EvolutionResources.errCantSplitMoreThanOriginalQty, $"txtTargetOrderQty{splitItem.RowNumber}_5_0"); } break; } else { // If we have a target order... if (splitItem.TargetOrderId != 0) { var tempPoh = db.FindPurchaseOrderHeader(splitItem.TargetOrderId); if (tempPoh != null) { // Found it, so check the base numbers (the value to the left of the decimal) if ((int)origPoh.OrderNumber != (int)tempPoh.OrderNumber) { // Base is different, but is target a root order ? if ((int)tempPoh.OrderNumber != tempPoh.OrderNumber) { // Target order isn't root error.SetError(EvolutionResources.errYouCannotMoveItemsToNonRootOrder, $"ddlTargetOrder{splitItem.RowNumber}_6_0"); break; } else { podList.Add(pod); } } else { // Base is the same, so valid target order podList.Add(pod); } } else { // Not found error.SetError(EvolutionResources.errMustSelectValidOrderNumber, $"ddlTargetOrder{splitItem.RowNumber}_6_0"); break; } } else { // No target order so make sure qty is 0 for target order if (splitItem.TargetOrderQty > 0) { error.SetError(EvolutionResources.errTargetQtyMustBeZeroWhenNoOrderSpecified, $"txtTargetOrderQty{splitItem.RowNumber}_6_0"); break; } else { podList.Add(pod); } } } } if (!error.IsError && numItems == 0) { error.SetError(EvolutionResources.errNoItemsHaveBeenSpecifiedToMoveOrSplit, ""); } } return(error); }
private Error doSplit(CompanyModel company, SplitPurchaseModel model, UserModel user) { var error = new Error(); string lgs; // Proceed to do the split for (int i = 0; i < podList.Count() && !error.IsError; i++) { var podListItem = podList[i]; var splitItem = model.SplitItems[i]; var updatedItem = updatedDetails.Items .Where(ud => ud.OriginalRowId == podListItem.Id) .FirstOrDefault(); PurchaseOrderDetailModel pod = new PurchaseOrderDetailModel { CompanyId = company.Id, PurchaseOrderHeaderId = 0, LineNumber = 0, ProductId = podListItem.ProductId.Value, ProductDescription = podListItem.ProductDescription, UnitPriceExTax = podListItem.UnitPriceExTax, TaxCodeId = podListItem.TaxCodeId, DiscountPercent = podListItem.DiscountPercent, //LineStatus = podListItem.LineStatus, //IsReceived = podListItem.IsReceived }; if (splitItem.NewOrderQty > 0) { // Add a new line to a new order if (newPoh == null) { // Create the new order first newPoh = mapToModel(updatedPoh); newPoh.Id = 0; newPoh.OrderNumber = LookupService.GetNextSequenceNumber(company, SequenceNumberType.PurchaseOrderNumber, 0, false); error = InsertOrUpdatePurchaseOrderHeader(newPoh, user, ""); } if (!error.IsError) { pod.PurchaseOrderHeaderId = newPoh.Id; pod.OrderQty = splitItem.NewOrderQty; pod.LineNumber = db.GetNextPurchaseOrderDetailLineNumber(pod.PurchaseOrderHeaderId, false); InsertOrUpdatePurchaseOrderDetail(pod, user, ""); // Move the # of split item allocations across to the new purchase order line pod.OrderQty -= splitItem.NewOrderQty; var allocList1 = updatedAllocations.Where(a => a.PurchaseLineId == pod.Id) .ToList(); AllocationService.AllocateOnPurchaseOrderSplit(updatedItem, allocList1, newPoh, pod, splitItem.NewOrderQty, user); } } if (!error.IsError && splitItem.TargetOrderQty > 0) { // Add a new line to the target order pod.Id = 0; pod.PurchaseOrderHeaderId = splitItem.TargetOrderId; pod.OrderQty = splitItem.TargetOrderQty; pod.LineNumber = db.GetNextPurchaseOrderDetailLineNumber(pod.PurchaseOrderHeaderId, false); error = InsertOrUpdatePurchaseOrderDetail(pod, user, ""); // Move the # of split item allocations across to the new purchase order line pod.OrderQty -= splitItem.TargetOrderQty; var allocList2 = updatedAllocations.Where(a => a.PurchaseLineId == pod.Id) .ToList(); AllocationService.AllocateOnPurchaseOrderSplit(updatedItem, allocList2, newPoh, pod, splitItem.TargetOrderQty, user); } if (!error.IsError) { InsertOrUpdatePurchaseOrderDetail(updatedItem, user, LockPurchaseOrderDetail(updatedItem)); } } if (!error.IsError) { // Obsolete the existing order origPoh.POStatus = LookupService.FindPurchaseOrderHeaderStatusByValueModel(PurchaseOrderStatus.Superceded).Id; lgs = LockPurchaseOrderHeader(origPoh); error = InsertOrUpdatePurchaseOrderHeader(origPoh, user, lgs); } return(error); }