JobRequisitionItemStockHoldingReserverGrid.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using Comal.Classes;
  2. using InABox.Clients;
  3. using InABox.Core;
  4. using InABox.DynamicGrid;
  5. using InABox.WPF;
  6. using NPOI.HSSF.Record;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Windows;
  11. using System.Windows.Media.Imaging;
  12. namespace PRSDesktop
  13. {
  14. public class JobRequisitionItemStockHoldingReserverGrid : DynamicDataGrid<StockHolding>, ISpecificGrid
  15. {
  16. Guid ProductID = Guid.Empty;
  17. Guid JobID = Guid.Empty;
  18. String RequiNumber = "";
  19. Guid RequiItemID = Guid.Empty;
  20. bool actionColumn = true;
  21. private readonly BitmapImage tick = PRSDesktop.Resources.tick.AsBitmapImage();
  22. private readonly BitmapImage changeNotAllowed = PRSDesktop.Resources.box.AsBitmapImage();
  23. public bool StockReserved = false;
  24. public JobRequisitionItemStockHoldingReserverGrid(Guid productid, Guid jobid, Guid requiItemID, string requinumber, bool actioncolumn = true)
  25. {
  26. ProductID = productid;
  27. JobID = jobid;
  28. RequiNumber = requinumber;
  29. RequiItemID = requiItemID;
  30. Options.AddRange(
  31. DynamicGridOption.FilterRows,
  32. DynamicGridOption.SelectColumns
  33. );
  34. HiddenColumns.Add(x => x.ID);
  35. HiddenColumns.Add(x => x.Location.ID);
  36. HiddenColumns.Add(x => x.Product.ID);
  37. HiddenColumns.Add(x => x.Style.ID);
  38. HiddenColumns.Add(x => x.Job.ID);
  39. HiddenColumns.Add(x => x.Job.Deleted);
  40. HiddenColumns.Add(x => x.Dimensions.UnitSize);
  41. HiddenColumns.Add(x => x.Dimensions.Unit.ID);
  42. HiddenColumns.Add(x => x.Dimensions.Unit.Description);
  43. HiddenColumns.Add(x => x.Dimensions.Unit.HasHeight);
  44. HiddenColumns.Add(x => x.Dimensions.Unit.HasLength);
  45. HiddenColumns.Add(x => x.Dimensions.Unit.HasWidth);
  46. HiddenColumns.Add(x => x.Dimensions.Unit.HasHeight);
  47. HiddenColumns.Add(x => x.Dimensions.Unit.HasQuantity);
  48. HiddenColumns.Add(x => x.Dimensions.Unit.Format);
  49. HiddenColumns.Add(x => x.Dimensions.Unit.Formula);
  50. HiddenColumns.Add(x => x.Dimensions.Length);
  51. HiddenColumns.Add(x => x.Dimensions.Width);
  52. HiddenColumns.Add(x => x.Dimensions.Height);
  53. HiddenColumns.Add(x => x.Dimensions.Quantity);
  54. actionColumn = actioncolumn;
  55. if (actioncolumn)
  56. ActionColumns.Add(new DynamicImageColumn(ConfirmedImage, ReserveStock));
  57. }
  58. protected override void GenerateColumns(DynamicGridColumns columns)
  59. {
  60. columns.Add<StockHolding, string>(x => x.Location.Description, 110, "Location", "", Alignment.MiddleLeft);
  61. columns.Add<StockHolding, string>(x => x.Product.Code, 70, "Product Code", "", Alignment.MiddleLeft);
  62. columns.Add<StockHolding, string>(x => x.Product.Name, 150, "Product Name", "", Alignment.MiddleLeft);
  63. columns.Add<StockHolding, string>(x => x.Job.JobNumber, 50, "Job", "", Alignment.MiddleLeft);
  64. columns.Add<StockHolding, string>(x => x.Style.Description, 150, "Style", "", Alignment.MiddleLeft);
  65. columns.Add<StockHolding, double>(x => x.Units, 50, "Units", "", Alignment.MiddleLeft);
  66. columns.Add<StockHolding, string>(x => x.Dimensions.UnitSize, 60, "Size", "", Alignment.MiddleLeft);
  67. }
  68. private bool ReserveStock(CoreRow row)
  69. {
  70. StockHolding holding = row.ToObject<StockHolding>();
  71. //if (holding.Job.IsValid())
  72. //{
  73. // CoreTable table = new Client<StockMovement>().Query(new Filter<StockMovement>(x => x.Location.ID).IsEqualTo(holding.ID)
  74. // .And(x => x.JobRequisitionItem.ID).IsEqualTo(RequiItemID),
  75. // new Columns<StockMovement>(x => x.ID));
  76. // if (table.Rows.Any())
  77. // {
  78. // var choiceresult = MessageBox.Show("This will reverse previous stock movements created to reserve from this location. Proceed?", "Alert", MessageBoxButton.YesNo);
  79. // switch (choiceresult)
  80. // {
  81. // case MessageBoxResult.Yes:
  82. // break;
  83. // case MessageBoxResult.No:
  84. // return false;
  85. // default:
  86. // return false;
  87. // }
  88. // List<StockMovement> movements = new List<StockMovement>();
  89. // foreach (CoreRow stockmovementRow in table.Rows)
  90. // {
  91. // StockMovement movement = new StockMovement { ID = Guid.Parse(stockmovementRow.Values[0].ToString()) };
  92. // movements.Add(movement);
  93. // }
  94. // new Client<StockMovement>().Delete(movements, "Stock movements reversed from Job Requi Review Dashboard");
  95. // return true;
  96. // }
  97. // else
  98. // {
  99. // MessageBox.Show("The stock movements for this holding cannot be reversed");
  100. // return false;
  101. // }
  102. //}
  103. var result = MessageBox.Show("This will reserve stock from the holding now. Proceed?", "Alert", MessageBoxButton.YesNo);
  104. switch (result)
  105. {
  106. case MessageBoxResult.Yes:
  107. break;
  108. case MessageBoxResult.No:
  109. return false;
  110. default:
  111. return false;
  112. }
  113. int units = Convert.ToInt32(holding.Units);
  114. if (NumberEdit.Execute("Enter number to reserve", 1, units, ref units))
  115. {
  116. StockMovementBatch batch = new StockMovementBatch();
  117. batch.Type = StockMovementBatchType.Transfer;
  118. batch.Notes = "Reserving Stock for Requi: " + RequiNumber;
  119. new Client<StockMovementBatch>().Save(batch, "Created from Job Requi Item Reserve Stock Screen");
  120. List<StockMovement> movements = new List<StockMovement>();
  121. StockMovement issuemovement = new StockMovement();
  122. issuemovement.System = true;
  123. issuemovement.Batch.Notes = batch.Notes;
  124. issuemovement.Batch.Type = StockMovementBatchType.Transfer;
  125. issuemovement.Units = units;
  126. issuemovement.Issued = units;
  127. issuemovement.Dimensions.CopyFrom(holding.Dimensions);
  128. issuemovement.Style.ID = holding.Style.ID;
  129. issuemovement.Location.ID = holding.Location.ID;
  130. issuemovement.Product.ID = holding.Product.ID;
  131. issuemovement.Date = batch.Created;
  132. issuemovement.IsTransfer = true;
  133. issuemovement.Notes = batch.Notes;
  134. issuemovement.JobRequisitionItem.ID = RequiItemID;
  135. issuemovement.Employee.ID = Guid.Parse(new Client<Employee>().Query(new Filter<Employee>(x => x.UserLink.UserID).IsEqualTo(ClientFactory.UserID), new Columns<Employee>(x => x.ID)).Rows.FirstOrDefault().Values[0].ToString());
  136. StockMovement receivemovement = new StockMovement();
  137. receivemovement.Batch.Notes = batch.Notes;
  138. receivemovement.Batch.Type = StockMovementBatchType.Transfer;
  139. receivemovement.Units = units;
  140. receivemovement.Received = units;
  141. receivemovement.Dimensions.CopyFrom(holding.Dimensions);
  142. receivemovement.Style.ID = holding.Style.ID;
  143. receivemovement.Location.ID = holding.Location.ID;
  144. receivemovement.Product.ID = holding.Product.ID;
  145. receivemovement.Date = batch.Created;
  146. receivemovement.IsTransfer = true;
  147. receivemovement.Notes = batch.Notes;
  148. receivemovement.JobRequisitionItem.ID = RequiItemID;
  149. receivemovement.Employee.ID = Guid.Parse(new Client<Employee>().Query(new Filter<Employee>(x => x.UserLink.UserID).IsEqualTo(ClientFactory.UserID), new Columns<Employee>(x => x.ID)).Rows.FirstOrDefault().Values[0].ToString());
  150. receivemovement.Job.ID = JobID;
  151. movements.Add(issuemovement);
  152. movements.Add(receivemovement);
  153. new Client<StockMovement>().Save(movements, "Items reserved from Job Requi Item Reserve Stock Screen");
  154. StockReserved = true;
  155. }
  156. return true;
  157. }
  158. private BitmapImage ConfirmedImage(CoreRow row)
  159. {
  160. if (row == null)
  161. return tick;
  162. StockHolding holding = row.ToObject<StockHolding>();
  163. if (holding.Job.ID == JobID)
  164. {
  165. CoreTable table = new Client<StockMovement>().Query(new Filter<StockMovement>(x => x.Location.ID).IsEqualTo(holding.ID)
  166. .And(x => x.JobRequisitionItem.ID).IsEqualTo(RequiItemID),
  167. new Columns<StockMovement>(x => x.ID));
  168. if (table.Rows.Any())
  169. {
  170. return tick;
  171. }
  172. else
  173. return changeNotAllowed;
  174. }
  175. else
  176. return null;
  177. }
  178. protected override void Reload(Filters<StockHolding> criteria, Columns<StockHolding> columns, ref SortOrder<StockHolding> sort, Action<CoreTable, Exception> action)
  179. {
  180. criteria.Add(new Filter<StockHolding>(x => x.Units).IsGreaterThan(0.0001));
  181. criteria.Add(new Filter<StockHolding>(x => x.Product.ID).IsEqualTo(ProductID));
  182. criteria.Add(new Filter<StockHolding>(x => x.Job).NotLinkValid().Or(x => x.Job).LinkValid(JobID));
  183. base.Reload(criteria, columns, ref sort, action);
  184. }
  185. }
  186. }