| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- using System;
- using System.Collections.Generic;
- using System.Linq.Expressions;
- using Comal.Classes;
- using InABox.Core;
- using Xamarin.Forms;
- namespace PRS.Mobile
- {
- public delegate void SaveMovementEvent(StockMovement movement);
- public partial class StockMovementPage
- {
- private StockMovement _movement = null;
- private StockHolding _holding = null;
- private StockMovementBatchType _type = StockMovementBatchType.Stocktake;
- public event SaveMovementEvent OnSaveMovement;
- double _qty = 0.0F;
- bool firstNotification = true;
- public StockMovementPage(StockHolding holding, StockMovement movement, ImageSource src, StockMovementBatchType type)
- {
- _holding = holding;
- _movement = movement;
- _type = type;
- InitializeComponent();
- StyleReadOnlyRow.Height = type != StockMovementBatchType.Transfer ? new GridLength(1.0, GridUnitType.Auto) : new GridLength(0.0, GridUnitType.Absolute);
- StyleRow.Height = type == StockMovementBatchType.Transfer ? new GridLength(1.0, GridUnitType.Auto) : new GridLength(0.0, GridUnitType.Absolute);
- ChangeStyle.IsVisible = type == StockMovementBatchType.Transfer;
- JobReadOnlyRow.Height = (type != StockMovementBatchType.Issue) && (type != StockMovementBatchType.Transfer) ? new GridLength(1.0, GridUnitType.Auto) : new GridLength(0.0, GridUnitType.Absolute);
- JobRow.Height = (type == StockMovementBatchType.Issue) || (type == StockMovementBatchType.Transfer) ? new GridLength(1.0, GridUnitType.Auto) : new GridLength(0.0, GridUnitType.Absolute);
- ChangeJob.IsVisible = (type == StockMovementBatchType.Issue) || (type == StockMovementBatchType.Transfer);
- LocationRow.Height = type == StockMovementBatchType.Transfer ? new GridLength(1.0, GridUnitType.Auto) : new GridLength(0.0, GridUnitType.Absolute);
- ChangeLocation.IsVisible = type == StockMovementBatchType.Transfer;
- ToolbarItems.Clear();
- ToolbarItems.Add(new ToolbarItem("Save", "", () =>
- {
- _movement.Received = 0.0F;
- _movement.Issued = 0.0F;
- if (_type == StockMovementBatchType.Issue)
- _movement.Issued = _qty;
- else if (_type == StockMovementBatchType.Receipt)
- _movement.Received = _qty;
- else if (_type == StockMovementBatchType.Transfer)
- _movement.Received = _qty;
- else
- {
- if (_qty < _holding.Units)
- _movement.Issued = _holding.Units - _qty;
- else
- _movement.Received = _qty - _holding.Units;
- }
- OnSaveMovement?.Invoke(_movement);
- Navigation.PopAsync();
- }));
- Title = String.Format("{0}: {1}",type.ToString(),holding.Product.Code);
- if (src != null)
- {
- Image.Source = src;
- ImageFrame.IsVisible = true;
- }
- else
- NoImageFrame.IsVisible = true;
- Description.Text = holding.Product.Name;
- StyleReadOnly.Text = String.Format("{0}: {1}", _movement.Style.Code, _movement.Style.Description);
- ChangeStyle.Text = String.Format("{0}: {1}", _movement.Style.Code, _movement.Style.Description);
- JobReadOnly.Text = _movement.Job.ID != Guid.Empty ? String.Format("{0}: {1}", _movement.Job.JobNumber, _movement.Job.Name) : "General Stock";
- ChangeJob.Text = _movement.Job.ID != Guid.Empty ? String.Format("{0}: {1}", _movement.Job.JobNumber, _movement.Job.Name) : "General Stock";
- ChangeLocation.Text = String.Format("{0}: {1}", _movement.Location.Code, _movement.Location.Description);
-
- _qty = type == StockMovementBatchType.Stocktake
- ? _holding.Units + movement.Received - movement.Issued
- : type == StockMovementBatchType.Issue
- ? movement.Issued
- : type == StockMovementBatchType.Receipt
- ? movement.Received
- : movement.Issued;
- Qty.Text = _qty.ToString();
- Qty.Placeholder = type == StockMovementBatchType.Stocktake
- ? "On Hand"
- : type == StockMovementBatchType.Issue
- ? "Issue"
- : type == StockMovementBatchType.Receipt
- ? "Receive"
- : "Transfer";
- }
- protected override void OnAppearing()
- {
- base.OnAppearing();
- firstNotification = true;
- }
- private void UpdateQty(double delta, bool update)
- {
- bool bOK = double.TryParse(Qty.Text, out double qty);
- if (bOK)
- {
- qty += delta;
- if (qty < 0.0F && _type == StockMovementBatchType.Stocktake) qty = 0.0F;
- if (qty < 0.0F && firstNotification)
- {
- firstNotification = false;
- DisplayAlert("Warning", "Are you correcting a mistake by using negative values? It will be flagged in the system as a correction.", "OK");
- _movement.Notes = _movement.Notes + "Transaction is a mistake correction. ";
- }
- _qty = qty;
- if (update)
- Qty.Text = qty.ToString();
- Qty.BackgroundColor = Color.WhiteSmoke;
- }
- else
- Qty.BackgroundColor = Color.LightSalmon;
- }
- void Qty_TextChanged(System.Object sender, Xamarin.Forms.TextChangedEventArgs e)
- {
- UpdateQty(0.0F, false);
- }
- void More_Clicked(System.Object sender, System.EventArgs e)
- {
- UpdateQty(1.0F, true);
- }
- void Less_Clicked(System.Object sender, System.EventArgs e)
- {
- UpdateQty(-1.0F, true);
- }
- void Job_Clicked(System.Object sender, System.EventArgs e)
- {
- GenericSelectionPage page = new GenericSelectionPage(
- "Select Job",
- new SelectionViewModel<Job>(
- new Filter<Job>(X => X.JobStatus.Active).IsEqualTo(true),
- new Expression<Func<Job, object>>[] { X => X.JobNumber, X => X.Name },
- new Expression<Func<Job, object>>[] { },
- new SortOrder<Job>(x => x.JobNumber)
- )
- );
- page.OnItemSelected += (o,e) => {
- var job = e.Row.ToObject<Job>();
- _movement.Job.ID = job.ID;
- _movement.Job.Synchronise(job);
- Dispatcher.BeginInvokeOnMainThread(() =>
- {
- ChangeJob.Text = job.ID != Guid.Empty ? String.Format("{0}: {1}", job.JobNumber, job.Name) : "General Stock";
- });
- };
- Navigation.PushAsync(page);
- }
- void Style_Clicked(System.Object sender, System.EventArgs e)
- {
- GenericSelectionPage page = new GenericSelectionPage(
- "Select Style",
- new SelectionViewModel<ProductStyle>(
- null,
- new Expression<Func<ProductStyle, object>>[] { X => X.Code, X => X.Description },
- new Expression<Func<ProductStyle, object>>[] { },
- new SortOrder<ProductStyle>(x => x.Code)
- )
- );
- page.OnItemSelected += (o,e) => {
- var style = e.Row.ToObject<ProductStyle>();
- _movement.Style.ID = style.ID;
- _movement.Style.Synchronise(style);
- Dispatcher.BeginInvokeOnMainThread(() =>
- {
- ChangeStyle.Text = String.Format("{0}: {1}", style.Code, style.Description);
- });
- };
- Navigation.PushAsync(page);
- }
- void Location_Clicked(System.Object sender, System.EventArgs e)
- {
- GenericSelectionPage page = new GenericSelectionPage(
- "Select Location",
- new SelectionViewModel<StockLocation>(
- new Filter<StockLocation>(X => X.Active).IsEqualTo(true),
- new Expression<Func<StockLocation, object>>[] { X => X.Code, X => X.Description },
- new Expression<Func<StockLocation, object>>[] { },
- new SortOrder<StockLocation>(x => x.Code)
- )
- );
- page.OnItemSelected += (o,e) => {
- var location = e.Row.ToObject<StockLocation>();
- _movement.Location.ID = location.ID;
- _movement.Location.Synchronise(location);
- Dispatcher.BeginInvokeOnMainThread(() =>
- {
- ChangeLocation.Text = String.Format("{0}: {1}", location.Code, location.Description);
- });
- };
- Navigation.PushAsync(page);
- }
- }
- }
|