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