From 76eba3ad84f7c960e762e3ea2e224d6e5ca44759 Mon Sep 17 00:00:00 2001 From: Thomas Savine Date: Fri, 6 Mar 2020 09:30:49 +0000 Subject: [PATCH] TS - Added transaction and commodity panels --- .../BusinessMgrMobile.projitems | 4 + .../App/Commands/SbmCommand_Commodity.cs | 38 ++ .../SbmCommand_Transaction_SalesOrder.cs | 38 ++ .../Mobile/App/SbmMainPage.cs | 20 ++ .../BusinessMgrMobile/Mobile/App/SbmMenu.cs | 24 +- .../Commodities/SbmMainPanel_Commodity.cs | 335 ++++++++++++++++++ .../Transactions/SbmMainPanel_Transaction.cs | 334 +++++++++++++++++ SaBusMgrMobCore/Mobile/Core/App/SbmMobile.cs | 4 + .../Mobile/Core/Forms/Views/SbmContentView.cs | 2 +- 9 files changed, 794 insertions(+), 5 deletions(-) create mode 100644 BusinessMgrMobile/BusinessMgrMobile/Mobile/App/Commands/SbmCommand_Commodity.cs create mode 100644 BusinessMgrMobile/BusinessMgrMobile/Mobile/App/Commands/SbmCommand_Transaction_SalesOrder.cs create mode 100644 BusinessMgrMobile/BusinessMgrMobile/Mobile/Forms/Panels/Main/Commodities/SbmMainPanel_Commodity.cs create mode 100644 BusinessMgrMobile/BusinessMgrMobile/Mobile/Forms/Panels/Main/Transactions/SbmMainPanel_Transaction.cs diff --git a/BusinessMgrMobile/BusinessMgrMobile/BusinessMgrMobile.projitems b/BusinessMgrMobile/BusinessMgrMobile/BusinessMgrMobile.projitems index 8e1cfb2..5875fd3 100644 --- a/BusinessMgrMobile/BusinessMgrMobile/BusinessMgrMobile.projitems +++ b/BusinessMgrMobile/BusinessMgrMobile/BusinessMgrMobile.projitems @@ -15,6 +15,8 @@ App.xaml + + @@ -33,9 +35,11 @@ + + diff --git a/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/Commands/SbmCommand_Commodity.cs b/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/Commands/SbmCommand_Commodity.cs new file mode 100644 index 0000000..f241262 --- /dev/null +++ b/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/Commands/SbmCommand_Commodity.cs @@ -0,0 +1,38 @@ +using Sarand.BusinessMgr.Core.App; +using Sarand.BusinessMgr.Mobile.Core.App; +using Sarand.BusinessMgr.Mobile.Forms.Pages.Templates; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Sarand.BusinessMgr.Mobile.App.Commands +{ + //======================================================================= + public class SbmCommand_Commodity : SbmCommand_Mobile + { + //------------------------------------------------------------------- + // Construction. + public SbmCommand_Commodity () : base(null) + { + } + + //------------------------------------------------------------------- + public override bool CanExecute (object commandParam) + { + //if (!SecurityProfile.Accounts.CanView) return false; + if (!SbmAppConsole.IsViewApplicable(UserContext, Sbm.View.Commodities)) return false; + return true; + } + + //------------------------------------------------------------------- + /// Execute command. + public override void Execute (object commandParam) + { + if (!CanExecute(commandParam)) return; + App.GetInstance().SbmMainPage.SwitchView(SbmMobile.MainView.Commodity, Page_Template_Main.PageBodyMode.SelfScrolling); + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/Commands/SbmCommand_Transaction_SalesOrder.cs b/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/Commands/SbmCommand_Transaction_SalesOrder.cs new file mode 100644 index 0000000..4efbb4c --- /dev/null +++ b/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/Commands/SbmCommand_Transaction_SalesOrder.cs @@ -0,0 +1,38 @@ +using Sarand.BusinessMgr.Core.App; +using Sarand.BusinessMgr.Mobile.Core.App; +using Sarand.BusinessMgr.Mobile.Forms.Pages.Templates; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Sarand.BusinessMgr.Mobile.App.Commands +{ + //======================================================================= + public class SbmCommand_Transaction_SalesOrder : SbmCommand_Mobile + { + //------------------------------------------------------------------- + // Construction. + public SbmCommand_Transaction_SalesOrder () : base(null) + { + } + + //------------------------------------------------------------------- + public override bool CanExecute (object commandParam) + { + //if (!SecurityProfile.Accounts.CanView) return false; + if (!SbmAppConsole.IsViewApplicable(UserContext, Sbm.View.Contacts_Associations_Supplier)) return false; + return true; + } + + //------------------------------------------------------------------- + /// Execute command. + public override void Execute (object commandParam) + { + if (!CanExecute(commandParam)) return; + App.GetInstance().SbmMainPage.SwitchView(SbmMobile.MainView.Transaction, Page_Template_Main.PageBodyMode.SelfScrolling); + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/SbmMainPage.cs b/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/SbmMainPage.cs index 5ea41bf..5120115 100644 --- a/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/SbmMainPage.cs +++ b/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/SbmMainPage.cs @@ -12,6 +12,8 @@ using Xamarin.Forms; using Sarand.BusinessMgr.Mobile.Core.Forms.Base; using Sarand.BusinessMgr.Mobile.Forms.Panels.Main; using Sarand.BusinessMgr.Mobile.Forms.Panels.Main.Accounts; +using Sarand.BusinessMgr.Mobile.Forms.Panels.Main.Transactions; +using Sarand.BusinessMgr.Mobile.Forms.Panels.Main.Commodities; namespace Sarand.BusinessMgr.Mobile.App { @@ -102,6 +104,24 @@ namespace Sarand.BusinessMgr.Mobile.App break; } //------------------------------------------------------- + // Transaction. + case SbmMobile.MainView.Transaction: + { + SbmMainPanel_Transaction.Config panelConfig = new SbmMainPanel_Transaction.Config(); + SbmMainPanel_Transaction loginPanel = new SbmMainPanel_Transaction(panelConfig); + mainPanel = loginPanel; + break; + } + //------------------------------------------------------- + // Commodity. + case SbmMobile.MainView.Commodity: + { + SbmMainPanel_Commodity.Config panelConfig = new SbmMainPanel_Commodity.Config(); + SbmMainPanel_Commodity loginPanel = new SbmMainPanel_Commodity(panelConfig); + mainPanel = loginPanel; + break; + } + //------------------------------------------------------- } } catch (Exception exc) { Logger.Warn(fn + " " + exc.GetLogMessage(6)); } diff --git a/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/SbmMenu.cs b/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/SbmMenu.cs index 66e91ac..99511e0 100644 --- a/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/SbmMenu.cs +++ b/BusinessMgrMobile/BusinessMgrMobile/Mobile/App/SbmMenu.cs @@ -47,12 +47,28 @@ namespace Sarand.BusinessMgr.Mobile.App if (homeCommand.CanExecute(null)) menuOptions.Add(new OptionData() { Caption = "Home", Command = homeCommand }); // Accounts. - List commodityCommands = new List(); - commodityCommands.Add(new OptionData() { Caption = "Customer", Command = new SbmCommand_Accounts_Customer() }); - commodityCommands.Add(new OptionData() { Caption = "Supplier", Command = new SbmCommand_Accounts_Supplier() }); - if (commodityCommands.Exists(item => item.Command.CanExecute(null))) + List accountsCommands = new List(); + accountsCommands.Add(new OptionData() { Caption = "Customer", Command = new SbmCommand_Accounts_Customer() }); + accountsCommands.Add(new OptionData() { Caption = "Supplier", Command = new SbmCommand_Accounts_Supplier() }); + if (accountsCommands.Exists(item => item.Command.CanExecute(null))) { menuOptions.Add(new OptionData() { Caption = "Accounts", Heading = true }); + menuOptions.AddRange(accountsCommands); + } + // Transactions. + List transactionCommands = new List(); + transactionCommands.Add(new OptionData() { Caption = "Sales order", Command = new SbmCommand_Transaction_SalesOrder() }); + if (transactionCommands.Exists(item => item.Command.CanExecute(null))) + { + menuOptions.Add(new OptionData() { Caption = "Transactions", Heading = true }); + menuOptions.AddRange(transactionCommands); + } + // Commodities. + List commodityCommands = new List(); + commodityCommands.Add(new OptionData() { Caption = "Commodities", Command = new SbmCommand_Commodity() }); + if (commodityCommands.Exists(item => item.Command.CanExecute(null))) + { + menuOptions.Add(new OptionData() { Caption = "Commodity", Heading = true }); menuOptions.AddRange(commodityCommands); } // Config. diff --git a/BusinessMgrMobile/BusinessMgrMobile/Mobile/Forms/Panels/Main/Commodities/SbmMainPanel_Commodity.cs b/BusinessMgrMobile/BusinessMgrMobile/Mobile/Forms/Panels/Main/Commodities/SbmMainPanel_Commodity.cs new file mode 100644 index 0000000..4c2fced --- /dev/null +++ b/BusinessMgrMobile/BusinessMgrMobile/Mobile/Forms/Panels/Main/Commodities/SbmMainPanel_Commodity.cs @@ -0,0 +1,335 @@ +using Sarand.Core.App; +using Sarand.Core.Base; +using Sarand.Core.Bus; +using Sarand.Core.Mobile.Forms.Controls; +using Sarand.Core.Mobile.Forms.Panels; +using Sarand.Core.Tasks; +using Sarand.BusinessMgr.Core.App; +using Sarand.BusinessMgr.Core.Bus; +using Sarand.BusinessMgr.Core.WebService; +using Sarand.BusinessMgr.Mobile.Core.App; +using Sarand.BusinessMgr.Mobile.Core.Forms.Pages; +using Sarand.BusinessMgr.Mobile.Core.Mgr; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Xamarin.Forms; + +namespace Sarand.BusinessMgr.Mobile.Forms.Panels.Main.Commodities +{ + //======================================================================= + public class SbmMainPanel_Commodity : SbmMainPanel_ItemList + { + //------------------------------------------------------------------- + // Definitions. + public enum FilterProperty + { + Code, + Description, + } + public enum PanelMode + { + InProgress, + } + public new class Config : SbmMainPanel_ItemList.Config + { + public PanelMode Mode { get; set; } = PanelMode.InProgress; + } + + //------------------------------------------------------------------- + // Data members. + private Config config; + private class Columns + { + public ColumnDfn Id { get; set; } + public ColumnDfn Name { get; set; } + public ColumnDfn DescBrief { get; set; } + public ColumnDfn Code { get; set; } + public ColumnDfn Status { get; set; } + } + private Columns cols = new Columns(); + private String commodityDoubleClickedPrefix = "CommodityDblClick#"; + + //------------------------------------------------------------------- + // Construction. + public SbmMainPanel_Commodity (Config config) : + base(config) + { + this.config = config; + // Columns. + cols.Id = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Id); + cols.Name = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Supplier_Name); + cols.DescBrief = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.DescBrief); + cols.Code = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Code); + cols.Status = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Status); + // Initialise components. + InitialiseComponents(); + } + + //------------------------------------------------------------------- + // Properties. + protected override String HeaderCaption { get { return "Commodities"; } } + + //------------------------------------------------------------------- + // I n i t i l i a s e C o m p o n e n t s + //------------------------------------------------------------------- + /// Control initialisation on construction. + protected override void InitialiseComponents () + { + base.InitialiseComponents(); + + ConfigureComponents(); + } + + //------------------------------------------------------------------- + // C o n f i g u r e C o m p o n e n t s + //------------------------------------------------------------------- + /// Control configuration that can be changed dynamically. + protected override void ConfigureComponents () + { + base.ConfigureComponents(); + + // Initial population. + RefreshItemList(); + } + + //------------------------------------------------------------------- + // P a n e l A c t i o n s + //------------------------------------------------------------------- + + //------------------------------------------------------------------- + // C o n t r o l A c t i v i t y + //------------------------------------------------------------------- + protected override void SetControlActivity () + { + } + protected override void SetControlsReadOnly () + { + } + + //------------------------------------------------------------------- + // I t e m L i s t + //------------------------------------------------------------------- + protected override List GetFilterPropertyTypes () + { + List filterPropertyTypes = new List(); + filterPropertyTypes.Add(new SacsFilterPropertyType((int)FilterProperty.Code, "Code") { Mode = SacsFilterPropertyType.FilterMode.Text }); + filterPropertyTypes.Add(new SacsFilterPropertyType((int)FilterProperty.Description, "Description") { Mode = SacsFilterPropertyType.FilterMode.Text }); + return filterPropertyTypes; + } + public SbmCommodity.Params GetCommodityParams (uint pageNo, ushort pageLength) + { + SbmCommodity.Params prmCommodity = new SbmCommodity.Params(); + // Filter. + prmCommodity.CodePartial = HeaderPanel.PanelFilter.GetFilterPropertyValue((int)FilterProperty.Code); + prmCommodity.DescBriefPartial = HeaderPanel.PanelFilter.GetFilterPropertyValue((int)FilterProperty.Description); + prmCommodity.StatusCat = SbmCommodity.StatusCat.NotDeleted; + // Mode. + if (config.Mode == PanelMode.InProgress) + //prmCommodity.StatusCat = SbmCommodity.StatusCat.OnHold; + // Paging. + prmCommodity.ResultsPaging.PageNo = pageNo; + prmCommodity.ResultsPaging.PageLength = pageLength; + // Sort. + prmCommodity.SortColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Id)); + return prmCommodity; + } + private SacsTaskData taskDataRefreshList = null; + protected override void RefreshItemList (uint pageNo = 1) + { + String fn = GetType().Name + ".RefreshItemList"; + + // Kill previous request. + if (taskDataRefreshList != null) + { + taskDataRefreshList.TriggerCancellation(); + taskDataRefreshList = null; + } + + // Clear existing list. + DisplayItemList(null, "Refreshing list. Please wait..."); + + // Refresh the list. + RefreshItemList(GetCommodityParams(pageNo, ItemsPerPage), taskDataRefreshList = new SacsTaskData(null)); + } + private void RefreshItemList (SbmCommodity.Params commodityParams, SacsTaskData taskDataRefreshList_Local) + { + String fn = GetType().Name + ".RefreshItemList"; + + // Query data after delay. + Device.StartTimer(TimeSpan.FromMilliseconds(250), () => + { + if (SacsSystem.DebugMode) Logger.Debug(fn + " Timer fired."); + Task.Run(async () => + { + try + { + // Configure request. + SbmWebServiceRequest.Config configRequest = new SbmWebServiceRequest.Config(); + configRequest.DataType = SbmWebServiceRequest.DataType.Commodity; + configRequest.RequestType = SbmWebServiceRequest.RequestType.QueryList; + configRequest.Context.InstanceDefinition = SbmGlobals_Mobile.SessionProfile.InstanceDefinition; + configRequest.Context.Debug = SacsSystem.DebugMode; + // Filter. + Dictionary filter = CommodityMgr.GetCommodityQueryFilter_Mobile(commodityParams); + + // Columns. + List queryColumns = new List() + { + cols.Id.DataName, + cols.Name.DataName, + cols.DescBrief.DataName, + cols.Code.DataName, + cols.Status.DataName, + }; + // Request User profile. + if (SacsSystem.DebugMode) Logger.Debug(fn + " Querying data - START"); + configRequest.RequestType = SbmWebServiceRequest.RequestType.QueryList; + SbmWebServiceClient.QueryListResponseData responseData = + await new SbmWebServiceClient().RequestQueryList(configRequest, filter, queryColumns, CommodityMgr.GetSortColumns_Mobile(commodityParams), taskDataRefreshList_Local); + if (SacsSystem.DebugMode) Logger.Debug(fn + " Querying data - END Items: " + (responseData?.Items.Count.ToString() ?? "None") + (taskDataRefreshList_Local.IsCancellationRequested ? " [Cancelled]" : "")); + + // Display item list. + Device.BeginInvokeOnMainThread(() => + { + DisplayItemList(responseData); + }); + } + catch (Exception exc) { if (SacsSystem.DebugMode) Logger.Warn(fn + " " + exc.GetLogMessage()); } + }, taskDataRefreshList_Local.CancellationToken) + .ContinueWith(task => + { + taskDataRefreshList_Local.Dispose(); + if (taskDataRefreshList == taskDataRefreshList_Local) + taskDataRefreshList = null; + }); + if (SacsSystem.DebugMode) Logger.Debug(fn + " Timer method complete."); + // Kill timer with false response. + return false; + }); + } + + //------------------------------------------------------------------- + protected override void DisplayItemList (SbmWebServiceClient.QueryListResponseData responseData, SacsMessage message = null) + { + // Refresh paging properties. + if (responseData != null) + HeaderPanel.SetPaging(responseData.PageNo, responseData.PageLength, responseData.Total > 0 ? responseData.Total : responseData.Count); + else HeaderPanel.SetPaging(0, 0, 0); + // Construct item list HTML. + string html = "" + GetCommodityListStyles().Concat("\n") + GetCommodityListScripts().Concat("\n") + ""; + if (message != null) + { + String messageClass = "inf"; + switch (message.MessageLevel) + { + case SaMessageLevel.Fatal: + case SaMessageLevel.Exception: + case SaMessageLevel.Error: + messageClass = "err"; + break; + case SaMessageLevel.Warning: + messageClass = "wrn"; + break; + } + html += "
" + message.Message + "
"; + } + if (responseData == null) + { } + else if (responseData.Items.Count > 0) + { + html += "
Commodities found: " + responseData.Items.Count + "
"; + int itemCount = 0; + foreach (var item in responseData.Items) + { + itemCount++; + html += "
"; + html += ""; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + SaStatus commodityStatus = SacsSystem.GetStatusForCode(item.GetValue(cols.Status.DataName)); + html += " "; + html += " "; + if (SacsSystem.DebugMode) + { + html += " "; + html += " "; + html += " "; + html += " "; + } + html += "
Name" + item.GetValue(cols.Name.DataName) + "Description" + item.GetValue(cols.DescBrief.DataName) + "
Code" + item.GetValue(cols.Code.DataName) + "Status" + SacsSystem.GetStatusDesc(commodityStatus) + "
Item" + itemCount + "Id" + SysId.ToString(item.GetIdValue(cols.Id.DataName)) + "
"; + html += "
"; + } + } + else html += "
No commodities found
"; + html += ""; + ItemListWebView.Html = html; + //Logger.Debug("HTML: " + html); + } + private List GetCommodityListStyles () + { + List styles = new List(GetItemListBaseStyles()); + styles.AddRange(new String[] + { + }); + return styles; + } + private List GetCommodityListScripts () + { + List scripts = new List(GetItemListBaseScripts()); + scripts.AddRange(new String[] + { + "" + }); + return scripts; + } + + //------------------------------------------------------------------- + // P a n e l E v e n t s + //------------------------------------------------------------------- + /// 'App' navigation events on Item List web view control. + protected override void ItemListWebView_AppNavigating (object sender, SaxWebView.AppNavigatingEventArgs eventArgs) + { + String fn = GetType().Name + ".ItemListWebView_AppNavigating"; + if (SacsSystem.DebugMode) Logger.Debug(fn + " AppAction: " + eventArgs.AppAction); + if (eventArgs.AppAction.StartsWithCI(commodityDoubleClickedPrefix)) + { + SysId commodityId = new SysId(StringUtil.ToInt(eventArgs.AppAction.Right(eventArgs.AppAction.Length - commodityDoubleClickedPrefix.Length))); + if (!SysId.IsValid(commodityId)) + { + DisplayAlert(HeaderCaption, "Invalid commodity commodity selected.", "OK"); + return; + } + + // Configure Commodity Commodity page. + // Data will be retrieved and validated by the page. + //SbmFormPage_Commodities_Commodities.Config pageConfig = new SbmFormPage_Commodities_Commodities.Config(); + //pageConfig.CommodityIdToUpdate = commodityId; + //pageConfig.ReadOnly = true; + //if (pageConfig.ReadOnly) pageConfig.NavigationMode = SbmFormPage.NavigationMode.Close; + //SbmFormPage_Commodities_Commodities commodityForm = new SbmFormPage_Commodities_Commodities(pageConfig); + //commodityRepairForm.Disappearing += (sender2, e2) => { }; + //SbmGlobals_Mobile.Application.MainPage.Navigation.PushModalAsync(commodityForm, false); + } + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/BusinessMgrMobile/BusinessMgrMobile/Mobile/Forms/Panels/Main/Transactions/SbmMainPanel_Transaction.cs b/BusinessMgrMobile/BusinessMgrMobile/Mobile/Forms/Panels/Main/Transactions/SbmMainPanel_Transaction.cs new file mode 100644 index 0000000..5cbf6f6 --- /dev/null +++ b/BusinessMgrMobile/BusinessMgrMobile/Mobile/Forms/Panels/Main/Transactions/SbmMainPanel_Transaction.cs @@ -0,0 +1,334 @@ +using Sarand.Core.App; +using Sarand.Core.Base; +using Sarand.Core.Bus; +using Sarand.Core.Mobile.Forms.Controls; +using Sarand.Core.Mobile.Forms.Panels; +using Sarand.Core.Tasks; +using Sarand.BusinessMgr.Core.App; +using Sarand.BusinessMgr.Core.Bus; +using Sarand.BusinessMgr.Core.WebService; +using Sarand.BusinessMgr.Mobile.Core.App; +using Sarand.BusinessMgr.Mobile.Core.Forms.Pages; +using Sarand.BusinessMgr.Mobile.Core.Mgr; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Xamarin.Forms; + +namespace Sarand.BusinessMgr.Mobile.Forms.Panels.Main.Transactions +{ + //======================================================================= + public class SbmMainPanel_Transaction : SbmMainPanel_ItemList + { + //------------------------------------------------------------------- + // Definitions. + public enum FilterProperty + { + Ref, + } + public enum PanelMode + { + InProgress, + } + public new class Config : SbmMainPanel_ItemList.Config + { + public PanelMode Mode { get; set; } = PanelMode.InProgress; + } + + //------------------------------------------------------------------- + // Data members. + private Config config; + private class Columns + { + public ColumnDfn Id { get; set; } + public ColumnDfn Name { get; set; } + public ColumnDfn AmountTot { get; set; } + public ColumnDfn Ref { get; set; } + public ColumnDfn Status { get; set; } + } + private Columns cols = new Columns(); + private String transactionDoubleClickedPrefix = "TransactionDblClick#"; + + //------------------------------------------------------------------- + // Construction. + public SbmMainPanel_Transaction (Config config) : + base(config) + { + this.config = config; + // Columns. + cols.Id = TransactionMgr.GetTransactionColumnDfn(SbmTransaction.Column.Id); + cols.Name = TransactionMgr.GetTransactionColumnDfn(SbmTransaction.Column.AssocTarget_Name); + cols.AmountTot = TransactionMgr.GetTransactionColumnDfn(SbmTransaction.Column.AmountTot); + cols.Ref = TransactionMgr.GetTransactionColumnDfn(SbmTransaction.Column.Ref); + cols.Status = TransactionMgr.GetTransactionColumnDfn(SbmTransaction.Column.Status); + // Initialise components. + InitialiseComponents(); + } + + //------------------------------------------------------------------- + // Properties. + protected override String HeaderCaption { get { return "Transactions"; } } + public virtual Sbm.TransactionType TransactionType { get; } = Sbm.TransactionType.SalesOrder; + + //------------------------------------------------------------------- + // I n i t i l i a s e C o m p o n e n t s + //------------------------------------------------------------------- + /// Control initialisation on construction. + protected override void InitialiseComponents () + { + base.InitialiseComponents(); + + ConfigureComponents(); + } + + //------------------------------------------------------------------- + // C o n f i g u r e C o m p o n e n t s + //------------------------------------------------------------------- + /// Control configuration that can be changed dynamically. + protected override void ConfigureComponents () + { + base.ConfigureComponents(); + + // Initial population. + RefreshItemList(); + } + + //------------------------------------------------------------------- + // P a n e l A c t i o n s + //------------------------------------------------------------------- + + //------------------------------------------------------------------- + // C o n t r o l A c t i v i t y + //------------------------------------------------------------------- + protected override void SetControlActivity () + { + } + protected override void SetControlsReadOnly () + { + } + + //------------------------------------------------------------------- + // I t e m L i s t + //------------------------------------------------------------------- + protected override List GetFilterPropertyTypes () + { + List filterPropertyTypes = new List(); + filterPropertyTypes.Add(new SacsFilterPropertyType((int)FilterProperty.Ref, "Ref") { Mode = SacsFilterPropertyType.FilterMode.Text }); + return filterPropertyTypes; + } + public SbmTransaction.Params GetTransactionParams (uint pageNo, ushort pageLength) + { + SbmTransaction.Params prmTransaction = new SbmTransaction.Params(); + // Filter. + prmTransaction.TransactionType = TransactionType; + prmTransaction.TransRefPartial = HeaderPanel.PanelFilter.GetFilterPropertyValue((int)FilterProperty.Ref); + prmTransaction.StatusCat = SbmTransaction.StatusCat.NotDeleted; + // Mode. + if (config.Mode == PanelMode.InProgress) + //prmTransaction.StatusCat = SbmTransaction.StatusCat.OnHold; + // Paging. + prmTransaction.ResultsPaging.PageNo = pageNo; + prmTransaction.ResultsPaging.PageLength = pageLength; + // Sort. + prmTransaction.SortColumns.Add(TransactionMgr.GetTransactionColumnDfn(SbmTransaction.Column.Id)); + return prmTransaction; + } + private SacsTaskData taskDataRefreshList = null; + protected override void RefreshItemList (uint pageNo = 1) + { + String fn = GetType().Name + ".RefreshItemList"; + + // Kill previous request. + if (taskDataRefreshList != null) + { + taskDataRefreshList.TriggerCancellation(); + taskDataRefreshList = null; + } + + // Clear existing list. + DisplayItemList(null, "Refreshing list. Please wait..."); + + // Refresh the list. + RefreshItemList(GetTransactionParams(pageNo, ItemsPerPage), taskDataRefreshList = new SacsTaskData(null)); + } + private void RefreshItemList (SbmTransaction.Params transactionParams, SacsTaskData taskDataRefreshList_Local) + { + String fn = GetType().Name + ".RefreshItemList"; + + // Query data after delay. + Device.StartTimer(TimeSpan.FromMilliseconds(250), () => + { + if (SacsSystem.DebugMode) Logger.Debug(fn + " Timer fired."); + Task.Run(async () => + { + try + { + // Configure request. + SbmWebServiceRequest.Config configRequest = new SbmWebServiceRequest.Config(); + configRequest.DataType = SbmWebServiceRequest.DataType.Transaction; + configRequest.RequestType = SbmWebServiceRequest.RequestType.QueryList; + configRequest.Context.InstanceDefinition = SbmGlobals_Mobile.SessionProfile.InstanceDefinition; + configRequest.Context.Debug = SacsSystem.DebugMode; + // Filter. + Dictionary filter = TransactionMgr.GetTransactionQueryFilter_Mobile(transactionParams); + + // Columns. + List queryColumns = new List() + { + cols.Id.DataName, + cols.Name.DataName, + cols.AmountTot.DataName, + cols.Ref.DataName, + cols.Status.DataName, + }; + // Request User profile. + if (SacsSystem.DebugMode) Logger.Debug(fn + " Querying data - START"); + configRequest.RequestType = SbmWebServiceRequest.RequestType.QueryList; + SbmWebServiceClient.QueryListResponseData responseData = + await new SbmWebServiceClient().RequestQueryList(configRequest, filter, queryColumns, TransactionMgr.GetSortColumns_Mobile(transactionParams), taskDataRefreshList_Local); + if (SacsSystem.DebugMode) Logger.Debug(fn + " Querying data - END Items: " + (responseData?.Items.Count.ToString() ?? "None") + (taskDataRefreshList_Local.IsCancellationRequested ? " [Cancelled]" : "")); + + // Display item list. + Device.BeginInvokeOnMainThread(() => + { + DisplayItemList(responseData); + }); + } + catch (Exception exc) { if (SacsSystem.DebugMode) Logger.Warn(fn + " " + exc.GetLogMessage()); } + }, taskDataRefreshList_Local.CancellationToken) + .ContinueWith(task => + { + taskDataRefreshList_Local.Dispose(); + if (taskDataRefreshList == taskDataRefreshList_Local) + taskDataRefreshList = null; + }); + if (SacsSystem.DebugMode) Logger.Debug(fn + " Timer method complete."); + // Kill timer with false response. + return false; + }); + } + + //------------------------------------------------------------------- + protected override void DisplayItemList (SbmWebServiceClient.QueryListResponseData responseData, SacsMessage message = null) + { + // Refresh paging properties. + if (responseData != null) + HeaderPanel.SetPaging(responseData.PageNo, responseData.PageLength, responseData.Total > 0 ? responseData.Total : responseData.Count); + else HeaderPanel.SetPaging(0, 0, 0); + // Construct item list HTML. + string html = "" + GetTransactionListStyles().Concat("\n") + GetTransactionListScripts().Concat("\n") + ""; + if (message != null) + { + String messageClass = "inf"; + switch (message.MessageLevel) + { + case SaMessageLevel.Fatal: + case SaMessageLevel.Exception: + case SaMessageLevel.Error: + messageClass = "err"; + break; + case SaMessageLevel.Warning: + messageClass = "wrn"; + break; + } + html += "
" + message.Message + "
"; + } + if (responseData == null) + { } + else if (responseData.Items.Count > 0) + { + html += "
Transactions found: " + responseData.Items.Count + "
"; + int itemCount = 0; + foreach (var item in responseData.Items) + { + itemCount++; + html += "
"; + html += ""; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + SaStatus transactionStatus = SacsSystem.GetStatusForCode(item.GetValue(cols.Status.DataName)); + html += " "; + html += " "; + if (SacsSystem.DebugMode) + { + html += " "; + html += " "; + html += " "; + html += " "; + } + html += "
Name" + item.GetValue(cols.Name.DataName) + "Cost" + item.GetValue(cols.AmountTot.DataName) + "
Ref" + item.GetValue(cols.Ref.DataName) + "Status" + SacsSystem.GetStatusDesc(transactionStatus) + "
Item" + itemCount + "Id" + SysId.ToString(item.GetIdValue(cols.Id.DataName)) + "
"; + html += "
"; + } + } + else html += "
No transactions found
"; + html += ""; + ItemListWebView.Html = html; + //Logger.Debug("HTML: " + html); + } + private List GetTransactionListStyles () + { + List styles = new List(GetItemListBaseStyles()); + styles.AddRange(new String[] + { + }); + return styles; + } + private List GetTransactionListScripts () + { + List scripts = new List(GetItemListBaseScripts()); + scripts.AddRange(new String[] + { + "" + }); + return scripts; + } + + //------------------------------------------------------------------- + // P a n e l E v e n t s + //------------------------------------------------------------------- + /// 'App' navigation events on Item List web view control. + protected override void ItemListWebView_AppNavigating (object sender, SaxWebView.AppNavigatingEventArgs eventArgs) + { + String fn = GetType().Name + ".ItemListWebView_AppNavigating"; + if (SacsSystem.DebugMode) Logger.Debug(fn + " AppAction: " + eventArgs.AppAction); + if (eventArgs.AppAction.StartsWithCI(transactionDoubleClickedPrefix)) + { + SysId transactionId = new SysId(StringUtil.ToInt(eventArgs.AppAction.Right(eventArgs.AppAction.Length - transactionDoubleClickedPrefix.Length))); + if (!SysId.IsValid(transactionId)) + { + DisplayAlert(HeaderCaption, "Invalid transaction transaction selected.", "OK"); + return; + } + + // Configure Transaction Transaction page. + // Data will be retrieved and validated by the page. + //SbmFormPage_Transactions_Transactions.Config pageConfig = new SbmFormPage_Transactions_Transactions.Config(); + //pageConfig.TransactionIdToUpdate = transactionId; + //pageConfig.ReadOnly = true; + //if (pageConfig.ReadOnly) pageConfig.NavigationMode = SbmFormPage.NavigationMode.Close; + //SbmFormPage_Transactions_Transactions transactionForm = new SbmFormPage_Transactions_Transactions(pageConfig); + //transactionRepairForm.Disappearing += (sender2, e2) => { }; + //SbmGlobals_Mobile.Application.MainPage.Navigation.PushModalAsync(transactionForm, false); + } + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/SaBusMgrMobCore/Mobile/Core/App/SbmMobile.cs b/SaBusMgrMobCore/Mobile/Core/App/SbmMobile.cs index 14a5605..b06daa9 100644 --- a/SaBusMgrMobCore/Mobile/Core/App/SbmMobile.cs +++ b/SaBusMgrMobCore/Mobile/Core/App/SbmMobile.cs @@ -38,6 +38,10 @@ namespace Sarand.BusinessMgr.Mobile.Core.App // Accounts. Customer, Supplier, + // Transactions. + Transaction, + // Commodities. + Commodity } //------------------------------------------------------------------- diff --git a/SaBusMgrMobCore/Mobile/Core/Forms/Views/SbmContentView.cs b/SaBusMgrMobCore/Mobile/Core/Forms/Views/SbmContentView.cs index 79ed613..17e5cdb 100644 --- a/SaBusMgrMobCore/Mobile/Core/Forms/Views/SbmContentView.cs +++ b/SaBusMgrMobCore/Mobile/Core/Forms/Views/SbmContentView.cs @@ -47,7 +47,7 @@ namespace Sarand.BusinessMgr.Mobile.Core.Forms.Views protected SbmDataItemMgr_Mobile DataItemMgr { get { if (dataItemMgr == null) dataItemMgr = new SbmDataItemMgr_Mobile(UserContext); return dataItemMgr; } } protected SbmProcessMgr_Mobile ProcessMgr { get { if (processMgr == null) processMgr = new SbmProcessMgr_Mobile(UserContext); return processMgr; } } protected SbmStockMgr_Mobile StockMgr { get { if (stockMgr == null) stockMgr = new SbmStockMgr_Mobile(UserContext); return stockMgr; } } - protected SbmTransactionMgr_Mobile BerthingMgr { get { if (transactionMgr == null) transactionMgr = new SbmTransactionMgr_Mobile(UserContext); return transactionMgr; } } + protected SbmTransactionMgr_Mobile TransactionMgr { get { if (transactionMgr == null) transactionMgr = new SbmTransactionMgr_Mobile(UserContext); return transactionMgr; } } public SbmWebServiceClient WebServiceClient { get { if (webServiceClient == null) webServiceClient = new SbmWebServiceClient(); return webServiceClient; } } //-------------------------------------------------------------------