Recall & Clone (Customer) Last Ticket (2 methods)

Here are 2 different methods to recall a Customer Last Ticket and Orders, and optionally Clone the Ticket. Personally, I prefer the 2nd method because it is “cleaner” and avoids unnecessary prompts.

The first method (this post) uses Entity Custom Data to store the Last Ticket Id and an Ask Question Action to determine if the user wants to Load Last Ticket.

The second method (2nd post) uses Entity State to store the Last Ticket Id and 2 Automation Command buttons to Load and Clone the Last Ticket.


FLOW:


Entity Custom Data Field to store LastTicketId:

Automation Command button to Clone Ticket:

Action - Ask Question Load Last Ticket:

Action - Clone Ticket:

Action - Load Ticket:

Action - Display Ticket:

Action - Load Entity by Search:

Action - Update Entity Data:

Action - Execute Automation Command:

:exclamation: All Rules which follow require a Default Mapping

Rule - Update Entity Data:

Rule - Clone Ticket:

Rule - Load Ticket:

Rule - Ask Question Load Ticket:

Rule - Entity Selected Load Entity Data:


DB Tools Export/Import file:

:heavy_exclamation_mark: You will still need to create the Custom Data Field for LastTicketId in the Customer Entity Type as shown in the first step of this Tutorial.

CustomerLastTicket.zip (1.4 KB)

3 Likes

Here is an alternative method that uses Entity State, and does not require Custom Data for the Customer Entity.

I also chose to remove the Ask Question Action; instead this method uses Automation Command buttons, so there is no unnecessary Prompts.

The other cool thing about this method is that you can Clone a Ticket that has no Customer Entity.

4 Likes

@QMcKay

2nd Method Display Ticket --> Clone Ticket did not bring sales tax is this only in mine?

i used Create Ticket action before with ‘true’ and had same problem.

It works properly on my system whether tied to a Customer or not…

if it’s tied to a customer it’s fine on my system just ticket from ticket viewer does like this

found the problem it was sales tax department mapping issue Solved now

I’ve tried to implement method 2, both by following the tutorial and, when it didn’t work, by using the database tools import. When I select customer then load last ticket, the ticket loads then SambaPOS crashes with “Exception has been thrown by the target of an invocation.” / “The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.”.

Clone ticket from Tickets (without customer selection) works fine.

I have also tried on a fresh database with sample data and it also crashes.

Any help would be much appreciated.

Full exception details below:

-----------------------------
[General Info]

Application: SambaPOS
Version:     4.1.82
Region:      en
DB:          CE
Machine:     MARK-PC
User:        Mark
Date:        11/06/2015
Time:        04:14

User Explanation:

Mark said ""

-----------------------------

[Exception Info 1]

Top-level Exception
Type:        System.Reflection.TargetInvocationException
Message:     Exception has been thrown by the target of an invocation.
Source:      mscorlib
Stack Trace: at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at Samba.Presentation.App.Main()

Inner Exception 1
Type:        System.ObjectDisposedException
Message:     The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
Source:      System.Data.Entity
Stack Trace: at System.Data.Objects.ObjectContext.EnsureConnection()
   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.Execute(MergeOption mergeOption)
   at System.Data.Objects.DataClasses.EntityReference`1.Load(MergeOption mergeOption)
   at System.Data.Objects.DataClasses.RelatedEnd.Load()
   at System.Data.Objects.DataClasses.RelatedEnd.DeferredLoad()
   at System.Data.Objects.Internal.LazyLoadBehavior.LoadProperty[TItem](TItem propertyValue, String relationshipName, String targetRoleName, Boolean mustBeNull, Object wrapperObject)
   at System.Data.Objects.Internal.LazyLoadBehavior.<>c__DisplayClass7`2.<GetInterceptorDelegate>b__2(TProxy proxy, TItem item)
   at System.Data.Entity.DynamicProxies.Ticket_381C97E9D1BA478AB2C6DD28254499465F84EABA0AB711950380101C07FAD3A1.get_TransactionDocument()
   at Samba.Domain.Models.Tickets.Ticket.Recalculate()
   at Samba.Presentation.Services.Implementations.TicketModule.TicketService.RecalculateTicket(Ticket ticket, Boolean forceRecalculation)
   at Samba.Modules.PosModule.TicketViewModel.ClearSelectedItems()
   at Samba.Modules.PosModule.TicketViewModel.ResetTicket()
   at Samba.Modules.PosModule.PosViewModel.OnTicketEvent(EventParameters`1 obj)
   at Microsoft.Practices.Prism.Events.EventSubscription`1.InvokeAction(Action`1 action, TPayload argument)
   at Microsoft.Practices.Prism.Events.EventSubscription`1.<>c__DisplayClass2.<GetExecutionStrategy>b__0(Object[] arguments)
   at Microsoft.Practices.Prism.Events.EventBase.InternalPublish(Object[] arguments)
   at Microsoft.Practices.Prism.Events.CompositePresentationEvent`1.Publish(TPayload payload)
   at Samba.Presentation.Services.Common.ExtensionMethods.Publish[TEventsubject](TEventsubject eventArgs, String eventTopic, Action expectedAction)

-----------------------------

[Assembly Info]

Samba.Services, Version=1.0.0.0
mscorlib, Version=4.0.0.0
System, Version=4.0.0.0
Microsoft.Practices.Prism, Version=4.0.0.0
WindowsBase, Version=4.0.0.0
Samba.Infrastructure, Version=1.0.0.0
Samba.Infrastructure.Data, Version=1.0.0.0
PresentationFramework, Version=4.0.0.0
System.Xaml, Version=4.0.0.0
Samba.Presentation.Services, Version=1.0.0.0
FluentValidation, Version=3.4.0.0
Samba.Domain, Version=1.0.0.0
DevExpress.Xpf.Grid.v14.1, Version=14.1.6.0
DevExpress.Xpf.Grid.v14.1.Core, Version=14.1.6.0
PresentationCore, Version=4.0.0.0
Stateless, Version=1.0.0.0
System.Core, Version=4.0.0.0
System.Drawing, Version=4.0.0.0
DevExpress.Xpf.Core.v14.1, Version=14.1.6.0
EntityFramework, Version=4.4.0.0
System.Windows.Forms, Version=4.0.0.0
System.ComponentModel.Composition, Version=4.0.0.0
Samba.Localization, Version=1.0.0.0
Microsoft.CSharp, Version=4.0.0.0
Microsoft.Practices.ServiceLocation, Version=1.0.0.0
Samba.Persistance, Version=1.0.0.0
Microsoft.Practices.Prism.MefExtensions, Version=4.0.0.0
PropertyTools, Version=2012.4.14.1

-----------------------------

[System Info]

Operating System
-Microsoft Windows 8.1 Pro
--CodeSet = 1252
--CSDVersion = 
--CurrentTimeZone = 480
--FreePhysicalMemory = 1768240
--OSArchitecture = 64-bit
--OSLanguage = 2057
--ServicePackMajorVersion = 0
--ServicePackMinorVersion = 0
--Version = 6.3.9600

Machine
-MARK-PC
--Manufacturer = Gigabyte Technology Co., Ltd.
--Model = To be filled by O.E.M.
--TotalPhysicalMemory = 8478597120
--UserName = Mark-PC\MARK-PC\Mark

-----------------------------

Try removing AC LT Load Ticket action from RU LT Load Last Ticket and leave AC LT Display Ticket action alone.

1 Like

Thanks @emre, it’s working now! :smile:

The “Load Last Ticket” button appears whenever a new ticket is created, but does not work unless a customer is first added. How can I make the button only visible if a customer has been selected on the ticket first? Been searching the forum but can’t find any visible states I can use for this…

Create a state and use entity updated rule to set it. Then map to that state

I can’t get it to work. What am I doing wrong?

Create State:

Create Entity Updated Rule: (for when a customer is selected / added to ticket)

Mapping on “Load Last Ticket” Automation Command:
(note I am testing it with Enabled state but eventually intend to add to Visible state)

I tried Status=IsCustomer and also just IsCustomer, neither work…

You do not have to define the state. You should probably research states more before you attempt it. You can really mess up the system if not fully grasped.

Entity selected rule works when you select an entity (for example when you click on a table) on entity screen. You should use Ticket Entity Changed rule instead.

Also don’t modify Status state as it is a default state. Define another state such as CStatus or Customer Status, etc.

1 Like