123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using NPOI.HSSF.Record;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Media.Imaging;
- namespace PRSDesktop
- {
- public class JobRequisitionItemStockHoldingReserverGrid : DynamicDataGrid<StockHolding>, ISpecificGrid
- {
- Guid ProductID = Guid.Empty;
- Guid JobID = Guid.Empty;
- String RequiNumber = "";
- Guid RequiItemID = Guid.Empty;
- bool actionColumn = true;
- private readonly BitmapImage tick = PRSDesktop.Resources.tick.AsBitmapImage();
- private readonly BitmapImage changeNotAllowed = PRSDesktop.Resources.box.AsBitmapImage();
- public bool StockReserved = false;
- public JobRequisitionItemStockHoldingReserverGrid(Guid productid, Guid jobid, Guid requiItemID, string requinumber, bool actioncolumn = true)
- {
- ProductID = productid;
- JobID = jobid;
- RequiNumber = requinumber;
- RequiItemID = requiItemID;
- Options.AddRange(
- DynamicGridOption.FilterRows,
- DynamicGridOption.SelectColumns
- );
- HiddenColumns.Add(x => x.ID);
- HiddenColumns.Add(x => x.Location.ID);
- HiddenColumns.Add(x => x.Product.ID);
- HiddenColumns.Add(x => x.Style.ID);
- HiddenColumns.Add(x => x.Job.ID);
- HiddenColumns.Add(x => x.Job.Deleted);
- HiddenColumns.Add(x => x.Dimensions.UnitSize);
- HiddenColumns.Add(x => x.Dimensions.Unit.ID);
- HiddenColumns.Add(x => x.Dimensions.Unit.Description);
- HiddenColumns.Add(x => x.Dimensions.Unit.HasHeight);
- HiddenColumns.Add(x => x.Dimensions.Unit.HasLength);
- HiddenColumns.Add(x => x.Dimensions.Unit.HasWidth);
- HiddenColumns.Add(x => x.Dimensions.Unit.HasHeight);
- HiddenColumns.Add(x => x.Dimensions.Unit.HasQuantity);
- HiddenColumns.Add(x => x.Dimensions.Unit.Format);
- HiddenColumns.Add(x => x.Dimensions.Unit.Formula);
- HiddenColumns.Add(x => x.Dimensions.Length);
- HiddenColumns.Add(x => x.Dimensions.Width);
- HiddenColumns.Add(x => x.Dimensions.Height);
- HiddenColumns.Add(x => x.Dimensions.Quantity);
- actionColumn = actioncolumn;
- if (actioncolumn)
- ActionColumns.Add(new DynamicImageColumn(ConfirmedImage, ReserveStock));
- }
- protected override void GenerateColumns(DynamicGridColumns columns)
- {
- columns.Add<StockHolding, string>(x => x.Location.Description, 110, "Location", "", Alignment.MiddleLeft);
- columns.Add<StockHolding, string>(x => x.Product.Code, 70, "Product Code", "", Alignment.MiddleLeft);
- columns.Add<StockHolding, string>(x => x.Product.Name, 150, "Product Name", "", Alignment.MiddleLeft);
- columns.Add<StockHolding, string>(x => x.Job.JobNumber, 50, "Job", "", Alignment.MiddleLeft);
- columns.Add<StockHolding, string>(x => x.Style.Description, 150, "Style", "", Alignment.MiddleLeft);
- columns.Add<StockHolding, double>(x => x.Units, 50, "Units", "", Alignment.MiddleLeft);
- columns.Add<StockHolding, string>(x => x.Dimensions.UnitSize, 60, "Size", "", Alignment.MiddleLeft);
- }
- private bool ReserveStock(CoreRow row)
- {
- StockHolding holding = row.ToObject<StockHolding>();
- //if (holding.Job.IsValid())
- //{
- // CoreTable table = new Client<StockMovement>().Query(new Filter<StockMovement>(x => x.Location.ID).IsEqualTo(holding.ID)
- // .And(x => x.JobRequisitionItem.ID).IsEqualTo(RequiItemID),
- // new Columns<StockMovement>(x => x.ID));
- // if (table.Rows.Any())
- // {
- // var choiceresult = MessageBox.Show("This will reverse previous stock movements created to reserve from this location. Proceed?", "Alert", MessageBoxButton.YesNo);
- // switch (choiceresult)
- // {
- // case MessageBoxResult.Yes:
- // break;
- // case MessageBoxResult.No:
- // return false;
- // default:
- // return false;
- // }
- // List<StockMovement> movements = new List<StockMovement>();
- // foreach (CoreRow stockmovementRow in table.Rows)
- // {
- // StockMovement movement = new StockMovement { ID = Guid.Parse(stockmovementRow.Values[0].ToString()) };
- // movements.Add(movement);
- // }
- // new Client<StockMovement>().Delete(movements, "Stock movements reversed from Job Requi Review Dashboard");
- // return true;
- // }
- // else
- // {
- // MessageBox.Show("The stock movements for this holding cannot be reversed");
- // return false;
- // }
- //}
- var result = MessageBox.Show("This will reserve stock from the holding now. Proceed?", "Alert", MessageBoxButton.YesNo);
- switch (result)
- {
- case MessageBoxResult.Yes:
- break;
- case MessageBoxResult.No:
- return false;
- default:
- return false;
- }
- int units = Convert.ToInt32(holding.Units);
- if (NumberEdit.Execute("Enter number to reserve", 1, units, ref units))
- {
- StockMovementBatch batch = new StockMovementBatch();
- batch.Type = StockMovementBatchType.Transfer;
- batch.Notes = "Reserving Stock for Requi: " + RequiNumber;
- new Client<StockMovementBatch>().Save(batch, "Created from Job Requi Item Reserve Stock Screen");
- List<StockMovement> movements = new List<StockMovement>();
- StockMovement issuemovement = new StockMovement();
- issuemovement.System = true;
- issuemovement.Batch.Notes = batch.Notes;
- issuemovement.Batch.Type = StockMovementBatchType.Transfer;
- issuemovement.Units = units;
- issuemovement.Issued = units;
- issuemovement.Dimensions.CopyFrom(holding.Dimensions);
- issuemovement.Style.ID = holding.Style.ID;
- issuemovement.Location.ID = holding.Location.ID;
- issuemovement.Product.ID = holding.Product.ID;
- issuemovement.Date = batch.Created;
- issuemovement.IsTransfer = true;
- issuemovement.Notes = batch.Notes;
- issuemovement.JobRequisitionItem.ID = RequiItemID;
- 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());
- StockMovement receivemovement = new StockMovement();
- receivemovement.Batch.Notes = batch.Notes;
- receivemovement.Batch.Type = StockMovementBatchType.Transfer;
- receivemovement.Units = units;
- receivemovement.Received = units;
- receivemovement.Dimensions.CopyFrom(holding.Dimensions);
- receivemovement.Style.ID = holding.Style.ID;
- receivemovement.Location.ID = holding.Location.ID;
- receivemovement.Product.ID = holding.Product.ID;
- receivemovement.Date = batch.Created;
- receivemovement.IsTransfer = true;
- receivemovement.Notes = batch.Notes;
- receivemovement.JobRequisitionItem.ID = RequiItemID;
- 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());
- receivemovement.Job.ID = JobID;
- movements.Add(issuemovement);
- movements.Add(receivemovement);
- new Client<StockMovement>().Save(movements, "Items reserved from Job Requi Item Reserve Stock Screen");
- StockReserved = true;
- }
- return true;
- }
- private BitmapImage ConfirmedImage(CoreRow row)
- {
- if (row == null)
- return tick;
- StockHolding holding = row.ToObject<StockHolding>();
- if (holding.Job.ID == JobID)
- {
- CoreTable table = new Client<StockMovement>().Query(new Filter<StockMovement>(x => x.Location.ID).IsEqualTo(holding.ID)
- .And(x => x.JobRequisitionItem.ID).IsEqualTo(RequiItemID),
- new Columns<StockMovement>(x => x.ID));
- if (table.Rows.Any())
- {
- return tick;
- }
- else
- return changeNotAllowed;
- }
- else
- return null;
- }
- protected override void Reload(Filters<StockHolding> criteria, Columns<StockHolding> columns, ref SortOrder<StockHolding> sort, Action<CoreTable, Exception> action)
- {
- criteria.Add(new Filter<StockHolding>(x => x.Units).IsGreaterThan(0.0001));
- criteria.Add(new Filter<StockHolding>(x => x.Product.ID).IsEqualTo(ProductID));
- criteria.Add(new Filter<StockHolding>(x => x.Job).NotLinkValid().Or(x => x.Job).LinkValid(JobID));
- base.Reload(criteria, columns, ref sort, action);
- }
- }
- }
|