|
@@ -1,4 +1,10 @@
|
|
|
-using System;
|
|
|
+using Comal.Classes;
|
|
|
+using InABox.Clients;
|
|
|
+using InABox.Core;
|
|
|
+using java.awt.@event;
|
|
|
+using net.sf.mpxj;
|
|
|
+using Syncfusion.UI.Xaml.Diagram.Theming;
|
|
|
+using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
@@ -20,28 +26,182 @@ namespace PRSDesktop
|
|
|
/// </summary>
|
|
|
public partial class JobRequisitionHoldingsReview : UserControl
|
|
|
{
|
|
|
+ List<Job> jobs = new List<Job>();
|
|
|
+
|
|
|
+ private JobRequisitionItem item;
|
|
|
+ public JobRequisitionItem Item
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ item = value;
|
|
|
+ SetHoldings();
|
|
|
+ SetStyle();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SetStyle()
|
|
|
+ {
|
|
|
+ if (Item.Style.ID != Guid.Empty)
|
|
|
+ CurrentStyleText.Text = Item.Style.Description + " (" + Item.Style.Code + ")";
|
|
|
+ else
|
|
|
+ CurrentStyleText.Text = "";
|
|
|
+ }
|
|
|
+
|
|
|
public JobRequisitionHoldingsReview()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
-
|
|
|
- List<JobRequiHoldingsReviewModel> list = new List<JobRequiHoldingsReviewModel>()
|
|
|
+ CoreTable table = new Client<Job>().Query(null, new Columns<Job>(x => x.ID, x => x.JobNumber));
|
|
|
+ foreach (var row in table.Rows)
|
|
|
{
|
|
|
- new JobRequiHoldingsReviewModel() {JobName = "A"},
|
|
|
- new JobRequiHoldingsReviewModel() {JobName = "B"},
|
|
|
- new JobRequiHoldingsReviewModel() {JobName = "C"},
|
|
|
- new JobRequiHoldingsReviewModel() {JobName = "D"},
|
|
|
- };
|
|
|
+ jobs.Add(row.ToObject<Job>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Button_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ private void SetHoldings()
|
|
|
+ {
|
|
|
+ CoreTable table = new Client<StockMovement>().Query(new Filter<StockMovement>(x => x.Product.ID).IsEqualTo(item.Product.ID),
|
|
|
+ new Columns<StockMovement>(
|
|
|
+ x => x.Style.ID,
|
|
|
+ x => x.Received,
|
|
|
+ x => x.Issued,
|
|
|
+ x => x.Location.ID,
|
|
|
+ x => x.Job.ID,
|
|
|
+ x => x.JobRequisitionItem.ID
|
|
|
+ ));
|
|
|
+ List<StockMovement> stockMovements = new List<StockMovement>();
|
|
|
+
|
|
|
+ foreach (CoreRow row in table.Rows)
|
|
|
+ stockMovements.Add(row.ToObject<StockMovement>());
|
|
|
+
|
|
|
+ List<JobRequiHoldingsReviewModel> list = new List<JobRequiHoldingsReviewModel>();
|
|
|
+ list.Add(SetHoldingsForJob(stockMovements));
|
|
|
+ list.Add(SetHoldingsForFreeStock(stockMovements));
|
|
|
+ list.AddRange(GetNonRequiHoldingsForOtherJobs(stockMovements));
|
|
|
listView.ItemsSource = list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JobRequiHoldingsReviewModel SetHoldingsForJob(List<StockMovement> mvts)
|
|
|
+ {
|
|
|
+ var currentJobHoldings = new JobRequiHoldingsReviewModel(item.Job.JobNumber + " (Not previously requi-ed)");
|
|
|
+ currentJobHoldings.GetStock(item.Job.ID, item.Style.ID, item.Product.ID, mvts);
|
|
|
+ currentJobHoldings.Background = new SolidColorBrush(Colors.LightGreen);
|
|
|
+ return currentJobHoldings;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JobRequiHoldingsReviewModel SetHoldingsForFreeStock(List<StockMovement> mvts)
|
|
|
+ {
|
|
|
+ var freeStock = new JobRequiHoldingsReviewModel("Free Stock (no job)");
|
|
|
+ freeStock.GetStock(Guid.Empty, item.Style.ID, item.Product.ID, mvts);
|
|
|
+ freeStock.Background = new SolidColorBrush(Colors.LightGreen);
|
|
|
+ return freeStock;
|
|
|
+ }
|
|
|
+
|
|
|
+ private IEnumerable<JobRequiHoldingsReviewModel> GetNonRequiHoldingsForOtherJobs(List<StockMovement> mvts)
|
|
|
+ {
|
|
|
+ var list = new List<JobRequiHoldingsReviewModel>();
|
|
|
+ foreach (var job in jobs)
|
|
|
+ {
|
|
|
+ if (job.ID == item.Job.ID)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ var holdings = new JobRequiHoldingsReviewModel(job.JobNumber);
|
|
|
+ holdings.GetStock(job.ID, item.Style.ID, item.Product.ID, mvts);
|
|
|
+
|
|
|
+ if (holdings.StockOfCurrentStyle == 0 && holdings.StockOfNoStyle == 0 && holdings.StockOfOtherStyles == 0)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ holdings.Background = new SolidColorBrush(Colors.Cornsilk);
|
|
|
+ list.Add(holdings);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public class JobRequiHoldingsReviewModel
|
|
|
- {
|
|
|
+ {
|
|
|
public string JobName { get; set; }
|
|
|
- public JobRequiHoldingsReviewModel()
|
|
|
+ public double StockOfCurrentStyle { get; set; }
|
|
|
+ public double StockOfNoStyle { get; set; }
|
|
|
+ public double StockOfOtherStyles { get; set; }
|
|
|
+
|
|
|
+ public Brush Background { get; set; }
|
|
|
+
|
|
|
+ Columns<StockMovement> columns = new Columns<StockMovement>(x => x.Received, x => x.Issued);
|
|
|
+
|
|
|
+ public JobRequiHoldingsReviewModel(string jobname)
|
|
|
+ {
|
|
|
+ JobName = jobname;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void GetStock(Guid jobid, Guid styleid, Guid productid, List<StockMovement> movements, bool bIncludeRequied = false)
|
|
|
+ {
|
|
|
+ GetStockOfCurrentStyle(jobid, styleid, movements, bIncludeRequied);
|
|
|
+ GetStockOfNoStyle(jobid, movements, bIncludeRequied);
|
|
|
+ GetStockOfOtherStyles(jobid, styleid, movements, bIncludeRequied);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void GetStockOfOtherStyles(Guid jobid, Guid styleid, List<StockMovement> movements, bool bIncludeRequied)
|
|
|
+ {
|
|
|
+ var mvts = movements
|
|
|
+ .Where(x => x.Job.ID == jobid)
|
|
|
+ .Where(x => x.Style.ID != Guid.Empty)
|
|
|
+ .Where(x => x.Style.ID != styleid)
|
|
|
+ .Where(x => x.JobRequisitionItem.ID == Guid.Empty);
|
|
|
+
|
|
|
+ StockOfOtherStyles = CalculateTotal(mvts);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void GetStockOfNoStyle(Guid jobid, List<StockMovement> movements, bool bIncludeRequied)
|
|
|
{
|
|
|
- JobName = "";
|
|
|
+ var mvts = movements
|
|
|
+ .Where(x => x.Job.ID == jobid)
|
|
|
+ .Where(x => x.Style.ID == Guid.Empty)
|
|
|
+ .Where(x => x.JobRequisitionItem.ID == Guid.Empty);
|
|
|
+
|
|
|
+ StockOfNoStyle = CalculateTotal(mvts);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void GetStockOfCurrentStyle(Guid jobid, Guid styleid, List<StockMovement> movements, bool bIncludeRequied)
|
|
|
+ {
|
|
|
+ if (styleid == Guid.Empty)
|
|
|
+ return;
|
|
|
+
|
|
|
+ var mvts = movements
|
|
|
+ .Where(x => x.Job.ID == jobid)
|
|
|
+ .Where(x => x.Style.ID == styleid)
|
|
|
+ .Where(x => x.JobRequisitionItem.ID == Guid.Empty);
|
|
|
+
|
|
|
+ StockOfCurrentStyle = CalculateTotal(mvts);
|
|
|
+ }
|
|
|
+
|
|
|
+ private double CalculateTotal(IEnumerable<StockMovement> mvts)
|
|
|
+ {
|
|
|
+ double total = 0;
|
|
|
+
|
|
|
+ double rec = 0;
|
|
|
+ double issued = 0;
|
|
|
+
|
|
|
+ foreach (var sm in mvts)
|
|
|
+ {
|
|
|
+ if (sm.Received != 0)
|
|
|
+ rec = rec + sm.Received;
|
|
|
+ else if (sm.Issued != 0)
|
|
|
+ issued = issued + sm.Issued;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rec >= issued)
|
|
|
+ total = rec - issued;
|
|
|
+
|
|
|
+ return total;
|
|
|
}
|
|
|
}
|
|
|
}
|