123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- using comal.timesheets.Manufacturing;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace comal.timesheets
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class ManufacturingPacketPopup
- {
- Guid _manufacturingPacketID = Guid.Empty;
- List<ManufacturingPacketStageShell> manufacturingPacketShells = new List<ManufacturingPacketStageShell>();
- List<AuditTrailShell> auditTrailShells = new List<AuditTrailShell>();
- public ManufacturingPacketPopup(Guid manufacturingpacketlinkID, Guid orderID)
- {
- InitializeComponent();
- _manufacturingPacketID = manufacturingpacketlinkID;
- LoadStages();
- LoadAuditTrail();
- if (orderID != Guid.Empty)
- LoadOrder(orderID);
- }
- private void LoadOrder(Guid orderID)
- {
- Task.Run(() =>
- {
- CoreTable table = QueryPurchaseOrderItem(orderID);
- while (table == null)
- table = QueryPurchaseOrderItem(orderID);
- if (table.Rows.Any())
- {
- var poItem = table.Rows.FirstOrDefault().ToObject<PurchaseOrderItem>();
- string dueDate = poItem.Consignment.EstimatedWarehouseArrival.ToString("dd MMM yy");
- string supplierName = poItem.PurchaseOrderLink.SupplierLink.Name;
- string recDate = poItem.ReceivedDate.ToString("dd MMM yy");
- if (poItem.ReceivedDate != DateTime.MinValue) //item has been received back to comal
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- ETAFrame.IsVisible = true;
- ETALbl.Text = "Item received from " + supplierName + " on " + recDate;
- });
- }
- else
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- ETAFrame.IsVisible = true;
- ETALbl.Text = "Item at " + supplierName + ", ETA: " + dueDate
- + System.Environment.NewLine + "(ETAs are auto-generated one week from date of purchase order creation)";
- });
- }
- }
- });
- }
- private CoreTable QueryPurchaseOrderItem(Guid orderID)
- {
- try
- {
- return new Client<PurchaseOrderItem>().Query
- (
- new Filter<PurchaseOrderItem>(x => x.ID).IsEqualTo(orderID),
- new Columns<PurchaseOrderItem>(x => x.Consignment.EstimatedWarehouseArrival,
- x => x.PurchaseOrderLink.SupplierLink.Name,
- x => x.ReceivedDate)
- );
- }
- catch (Exception ex)
- {
- InABox.Mobile.MobileLogging.Log(ex);
- return null;
- }
- }
- private void LoadStages()
- {
- Task.Run(() =>
- {
- CoreTable table = QueryStages();
- while (table == null)
- table = QueryStages();
- if (table.Rows.Any())
- {
- foreach (CoreRow row in table.Rows)
- {
- List<object> list = row.Values;
- if (list[2] == null) { list[2] = 0.0; } //2
- if (list[3] == null) { list[3] = ""; } //3
- ManufacturingPacketStageShell shell = new ManufacturingPacketStageShell()
- {
- PercentageComplete = list[2].ToString() + "%",
- ManufacturingSectionLinkName = list[3].ToString(),
- };
- Device.BeginInvokeOnMainThread(() =>
- {
- FactoryStageContentView factoryStageContentView = new FactoryStageContentView(shell);
- stageStackLayout.Children.Add(factoryStageContentView);
- });
- }
- }
- else
- {
- AddDefaults();
- }
- });
- }
- private CoreTable QueryStages()
- {
- try
- {
- return new Client<ManufacturingPacketStage>().Query(
- new Filter<ManufacturingPacketStage>(x => x.Parent.ID).IsEqualTo(_manufacturingPacketID),
- new Columns<ManufacturingPacketStage>(
- x => x.Station, //0
- x => x.Sequence, //1
- x => x.PercentageComplete, //2
- x => x.ManufacturingSectionLink.Name, //3
- x => x.QualityNotes //4
- ),
- new SortOrder<ManufacturingPacketStage>(x => x.Sequence, SortDirection.Ascending)
- );
- }
- catch (Exception ex)
- {
- InABox.Mobile.MobileLogging.Log(ex);
- return null;
- }
- }
- private void AddDefaults()
- {
- ManufacturingPacketStageShell shell = new ManufacturingPacketStageShell()
- {
- PercentageComplete = "0%",
- ManufacturingSectionLinkName = "Progress",
- };
- Device.BeginInvokeOnMainThread(() =>
- {
- FactoryStageContentView factoryStageContentView = new FactoryStageContentView(shell);
- stageStackLayout.Children.Add(factoryStageContentView);
- });
- }
- private void LoadAuditTrail()
- {
- Task.Run(() =>
- {
- CoreTable table = QueryAuditTrail();
- while (table == null)
- table = QueryAuditTrail();
- if (table.Rows.Any())
- {
- foreach (CoreRow row in table.Rows)
- {
- List<object> list = row.Values;
- if (list[0] == null) { list[0] = DateTime.MinValue; } //0
- if (list[1] == null) { list[1] = ""; } //1
- if (list[2] == null) { list[2] = ""; } //2
- AuditTrailShell shell = new AuditTrailShell()
- {
- Timestamp = DateTime.Parse(list[0].ToString()).ToString("dd MMM yy"),
- User = list[1].ToString(),
- Note = list[2].ToString()
- };
- auditTrailShells.Add(shell);
- }
- Device.BeginInvokeOnMainThread(() =>
- {
- auditListView.ItemsSource = auditTrailShells;
- });
- }
- });
- }
- private CoreTable QueryAuditTrail()
- {
- try
- {
- return new Client<AuditTrail>().Query(
- new Filter<AuditTrail>(x => x.EntityID).IsEqualTo(_manufacturingPacketID),
- new Columns<AuditTrail>(
- x => x.Timestamp, //0
- x => x.User, //1
- x => x.Note //2
- ),
- new SortOrder<AuditTrail>(x => x.Timestamp, SortDirection.Ascending)
- );
- }
- catch (Exception ex)
- {
- InABox.Mobile.MobileLogging.Log(ex);
- return null;
- }
- }
- }
- public class ManufacturingPacketStageShell
- {
- public int Station { get; set; }
- public long Sequence { get; set; }
- public string PercentageComplete { get; set; }
- public string ManufacturingSectionLinkName { get; set; }
- public ManufacturingPacketStageShell()
- {
- Station = 0;
- Sequence = 0;
- PercentageComplete = "";
- ManufacturingSectionLinkName = "";
- }
- }
- public class AuditTrailShell
- {
- public string Timestamp { get; set; }
- public string User { get; set; }
- public string Note { get; set; }
- public AuditTrailShell()
- {
- Timestamp = "";
- User = "";
- Note = "";
- }
- }
- }
|