DeliveryItemExtensions.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System.Collections.Generic;
  2. using InABox.Core;
  3. namespace Comal.Classes
  4. {
  5. public static class DeliveryItemExtensions
  6. {
  7. public static DeliveryItem CreateDeliveryItem(this PurchaseOrderItem item)
  8. {
  9. var result = new DeliveryItem();
  10. result.OrderItem.ID = item.ID;
  11. result.JobLink.ID = item.Job.ID;
  12. result.JobLink.Synchronise(item.Job);
  13. result.DueDate = item.ReceivedDate;
  14. result.Description = string.Format("{0} x {1}", item.Qty, item.Description);
  15. result.Title = result.Description;
  16. result.Piece = result.Description;
  17. result.Cost = item.Cost;
  18. return result;
  19. }
  20. public static DeliveryItem CreateDeliveryItem(this RequisitionItem item, Requisition requisition)
  21. {
  22. var result = new DeliveryItem();
  23. result.RequisitionLink.ID = requisition.ID;
  24. result.JobLink.ID = requisition.JobLink.ID;
  25. result.JobLink.Synchronise(requisition.JobLink);
  26. result.Delivery.ID = requisition.Delivery.ID;
  27. result.Delivery.Synchronise(requisition.Delivery);
  28. result.DueDate = requisition.Due;
  29. result.Description = string.Format("{0} ({1} off)", item.Description, item.Quantity);
  30. result.Title = item.Code;
  31. result.Piece = item.Code;
  32. return result;
  33. }
  34. public static IEnumerable<DeliveryItem> CreateDeliveryItems(this ManufacturingPacket entity, int From)
  35. {
  36. var result = new List<DeliveryItem>();
  37. // If the (new system) barcode qty is set, always use that - otherwise use the old system (Grouped/individual/none)
  38. var iCount = entity.BarcodeQty > 0 ? entity.BarcodeQty :
  39. entity.BarcodeType == BarcodeType.None ? 0 :
  40. entity.BarcodeType == BarcodeType.Grouped ? 1 : entity.Quantity;
  41. for (var iSeq = 1; iSeq <= iCount; iSeq++)
  42. {
  43. var item = new DeliveryItem();
  44. item.ManufacturingPacketLink.ID = entity.ID;
  45. //item.CustomAttributes = entity.CustomAttributes;
  46. //if (item.CustomAttributes != null)
  47. //{
  48. // StringBuilder sb = new StringBuilder();
  49. // if (item.CustomAttributes != null)
  50. // {
  51. // foreach (var attribute in item.CustomAttributes)
  52. // sb.AppendLine(String.Format("{0}={1}", attribute.Name, attribute.Value));
  53. // }
  54. // item.Attributes = sb.ToString();
  55. //}
  56. item.SetoutLink.ID = entity.SetoutLink.ID;
  57. item.SetoutLink.Synchronise(entity.SetoutLink);
  58. item.JobLink.ID = entity.SetoutLink.JobLink.ID;
  59. item.JobLink.Synchronise(entity.SetoutLink.JobLink);
  60. item.DueDate = entity.DueDate;
  61. if (iCount > 1)
  62. {
  63. item.Piece = string.Format("{0}{1:D2}", entity.ManufacturingTemplateLink.Code, iSeq);
  64. item.Title = string.Format("{0} ({1}/{2})", CoreUtils.StripHTML(entity.SetoutLink.Description), iSeq, iCount);
  65. item.Description = string.Format("{0} ({1}/{2})", entity.Title, iSeq, iCount);
  66. }
  67. else
  68. {
  69. item.Piece = entity.ManufacturingTemplateLink.Code;
  70. item.Title = string.Format("{0} ({1} unit{2})", entity.SetoutLink.Description, entity.Quantity, entity.Quantity > 1 ? "s" : "");
  71. item.Description = string.Format("{0} ({1} unit{2})", entity.Title, entity.Quantity, entity.Quantity > 1 ? "s" : "");
  72. }
  73. item.Sequence = From + iSeq;
  74. item.Height = entity.Height;
  75. item.Width = entity.Width;
  76. item.Length = entity.Length;
  77. var props = entity.UserProperties.AsDictionary;
  78. foreach (var key in props.Keys)
  79. if (item.UserProperties.ContainsKey(key))
  80. item.UserProperties[key] = props[key];
  81. result.Add(item);
  82. }
  83. return result;
  84. }
  85. }
  86. }