# Stop ticket re-opening after WP Closed

**URL:** <https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063>\
**Category:** V5 Question\
**Created:** [April 26, 2020, 8:58pm UTC](https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063 "2020-04-26T20:58:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashmiller](https://forum.sambapos.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@ashmiller](https://forum.sambapos.com/u/ashmiller)\
**Post date:** [April 26, 2020, 8:58pm UTC](https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063/1 "2020-04-26T20:58:56Z")

</div>

Hi,

I was wondering if there is a way to enable ticket re-opening for the tickets that have been opened that day (which I managed to do with Reopen closed ticket), but to make it impossible once the work period has been closed ?

In France, a tax law makes it obligatory to stop tickets being reopened after the day has ended.

Thanks for your help !

---

<div class="post-metadata">

**Author:** ![Bob\_be](https://forum.sambapos.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@Bob\_be](https://forum.sambapos.com/u/Bob_be)\
**Post date:** [April 26, 2020, 11:27pm UTC](https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063/2 "2020-04-26T23:27:22Z")

</div>

You could add a constraint that Ticket Date must equal Date. However if you are open past midnight, this may not a solution.

---

<div class="post-metadata">

**Author:** ![Memo](https://forum.sambapos.com/user_avatar/forum.sambapos.com/memo/32/55443_2.png) [@Memo](https://forum.sambapos.com/u/Memo)\
**Post date:** [April 27, 2020, 1:38am UTC](https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063/3 "2020-04-27T01:38:49Z")

</div>

**I’ve edited this post to work with current work periods**

I’ll be reusing actions/rules from the following tutorial:

> [@Re-open Settled Ticket & Cancel Payments](https://forum.sambapos.com/t/re-open-settled-ticket-cancel-payments/1600):
>
> The short version of this originally posted here: Enable More Ticket Actions Module from Samba Market. This module enables Reopen Closed Ticket and Cancel Payments action types. Create two actions for both of these action types. These actions do not have parameters. Create “Display Ticket” action, name it Refresh Ticket. Set TicketId parameter as 0. Create an Automation Command, name it as you wish an place it somewhere suitable. Create a Rule to handle this command and call Actions Reo…

With the above tutorial, I did not see anywhere where the ticket number or ID is passed to any actions/rules.

The way around it is to manually enter the ticket number (visible on the top left of the ticket). There may be another way, but I know this one works.

Script:

Script Name: Reopen Check  
Handler: reopen

```
function check(ticketid)
{
  qtd = "SELECT FORMAT(Date, 'yyyy-MM-ddTHH:mm:ss') FROM Tickets WHERE Id = '"+ticketid+"'";
  var rtd = sql.Exec(qtd)[0];
  
  qwp = "SELECT FORMAT(StartDate, 'yyyy-MM-ddTHH:mm:ss') FROM WorkPeriods WHERE Id = (SELECT MAX(Id) FROM WorkPeriods WHERE StartDate = EndDate)";
  var rwp = sql.Exec(qwp)[0];

  if (rtd >= rwp)
    {
      return 1;
    }
  else
    {
      return 0;
    }
}

```

Actions:

![26-04-2020_19;08_1587949710_Samba.Presentation](https://forum.sambapos.com/uploads/default/original/3X/f/f/ff5309eca03c2407b9bd26bae8ed867a7c758a17.png)  
Action Name: Reopen - Load Ticket  
Action Type: Load Ticket  
Ticket Number: [:Ticket Number]

![26-04-2020_19;08_1587949727_Samba.Presentation](https://forum.sambapos.com/uploads/default/original/3X/6/d/6d8a351368618a06d75b841fc6feff1abe2989bb.png)  
(if you don’t already have one)  
Action Name: Execute Automation Command  
Action Type: Execute Automation Command  
Automation Command Name: [:Command Name]  
Command Value: [:Command Value]

![26-04-2020_19;32_1587951167_Samba.Presentation](https://forum.sambapos.com/uploads/default/original/3X/a/9/a988c9ef37770102a6f763104cda32d6448745b1.png)  
Action Name: MSG TEST  
Action Type: Show Message  
Message: [:Message]

Rules:  
 ![26-04-2020_19;34_1587951291_Samba.Presentation](https://forum.sambapos.com/uploads/default/original/3X/3/7/37e300614e526d5b113ca73d627d8baabd408c14.png)  
 ![26-04-2020_21;56_1587959798_Samba.Presentation](https://forum.sambapos.com/uploads/default/original/3X/0/f/0ffda9ca292db7ea819763947f444122142c7d3d.png)  
Rule Name: Reopen  
Event Name: Automation Command Executed  
Execute Rule if: [Matches]  
Custom Constraint:  
\*\*Automation Command [Equals] Reopen  
\*\* or set this to the button you currently have visible on the ticket screen

Actions to Add:

Action: Reopen - Load Ticket  
Constraint:  
Ticket Number: [?Ticket Number;\d\*;;OCN]

Action: Execute Automation Command  
Constraint: {CALL:reopen.check(‘{TICKET ID}’)} == 1  
Command Name: Reopen - Reopen Ticket  
Command Value: {TICKET ID}

Action: MSG TEST  
Constraint: {CALL:reopen.check(‘{TICKET ID}’)} == 0  
Message: Ticket out-of-range\rUnable to reopen

![26-04-2020_19;09_1587949770_Samba.Presentation](https://forum.sambapos.com/uploads/default/original/3X/3/a/3a783e4aa16634b9758fed537fc6a21535af4db1.png)  
Change the Custom Constraint for RU Reopen Settled Ticket:

Custom Constraint:  
Automation Command Name [Equals] Reopen - Reopen Ticket

Reopening ticket from today:  
 ![26-04-2020_19;30_1587951018_%pn](https://forum.sambapos.com/uploads/default/original/3X/4/3/4366a0048c1326bcd359c8a375ca0b752792ac6e.gif)

Reopening ticket from not today:  
 ![26-04-2020_19;43_1587951818_%pn](https://forum.sambapos.com/uploads/default/original/3X/e/9/e926db71f31fe755afde7b1d30c05442f9e6f7b9.gif)

EDIT: Updated script

---

<div class="post-metadata">

**Author:** ![Memo](https://forum.sambapos.com/user_avatar/forum.sambapos.com/memo/32/55443_2.png) [@Memo](https://forum.sambapos.com/u/Memo)\
**Post date:** [April 27, 2020, 5:11am UTC](https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063/4 "2020-04-27T05:11:55Z")

</div>

I was just thinking, you could combine this with ticket logging for better tracking.

---

<div class="post-metadata">

**Author:** ![ashmiller](https://forum.sambapos.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@ashmiller](https://forum.sambapos.com/u/ashmiller)\
**Post date:** [April 27, 2020, 11:17am UTC](https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063/5 "2020-04-27T11:17:50Z")

</div>

Wow, thanks !

I’ll give it a try 😉

---

<div class="post-metadata">

**Author:** ![Memo](https://forum.sambapos.com/user_avatar/forum.sambapos.com/memo/32/55443_2.png) [@Memo](https://forum.sambapos.com/u/Memo)\
**Post date:** [April 27, 2020, 2:10pm UTC](https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063/6 "2020-04-27T14:10:07Z")

</div>

Change the script to the following (I didn’t test with a closed work period - this will work if WP is closed):

```
function check(ticketid)
{
  qtd = "SELECT FORMAT(Date, 'yyyy-MM-ddTHH:mm:ss') FROM Tickets WHERE Id = '"+ticketid+"'";
  var rtd = sql.Exec(qtd)[0];
  
  qwp = "SELECT FORMAT(StartDate, 'yyyy-MM-ddTHH:mm:ss') FROM WorkPeriods WHERE Id = (SELECT MAX(Id) FROM WorkPeriods WHERE StartDate = EndDate)";
  var rwp = sql.Exec(qwp)[0];

  if (rtd >= rwp)
    {
      return 1;
    }
  else
    {
      return 0;
    }
}
```

---

<div class="post-metadata">

**Author:** ![Bob\_be](https://forum.sambapos.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@Bob\_be](https://forum.sambapos.com/u/Bob_be)\
**Post date:** [April 27, 2020, 2:43pm UTC](https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063/7 "2020-04-27T14:43:42Z")

</div>

I was thinking something a little less exciting. Just add a Custom Constraint:  
 ![T1kZVARpb0](https://forum.sambapos.com/uploads/default/original/3X/f/a/faf23fc29453820d164290564d74421ce243a439.png)

```
{TICKET DATE} Equals {DATE}

```

I like the idea of another rule to show a message about not being able to reopen ticket.

Of course the non-exciting way would be duplicate the rule, change `{TICKET DATE} Equals {DATE}’ to ‘{TICKET DATE} **Not Equals** {DATE}’, remove all actions and add the Show Message action.

---

<div class="post-metadata">

**Author:** ![JTRTech](https://forum.sambapos.com/user_avatar/forum.sambapos.com/jtrtech/32/21270_2.png) [@JTRTech](https://forum.sambapos.com/u/JTRTech)\
**Post date:** [April 27, 2020, 6:48pm UTC](https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063/8 "2020-04-27T18:48:55Z")

</div>

That sounds viable provided single work period per day and not spanning days ie after midnight.

---

<div class="post-metadata">

**Author:** ![Memo](https://forum.sambapos.com/user_avatar/forum.sambapos.com/memo/32/55443_2.png) [@Memo](https://forum.sambapos.com/u/Memo)\
**Post date:** [April 27, 2020, 11:02pm UTC](https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063/9 "2020-04-27T23:02:15Z")

</div>

> [@Bob\_be](#):
>
> I was thinking something a little less exciting. Just add a Custom Constraint:

That was my original thought; you can see it going back to the original in the edits. But then I forgot about the WP requirement. Pesky details…

---

<div class="post-metadata">

**Author:** ![Bob\_be](https://forum.sambapos.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@Bob\_be](https://forum.sambapos.com/u/Bob_be)\
**Post date:** [April 27, 2020, 11:33pm UTC](https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063/10 "2020-04-27T23:33:44Z")

</div>

This quarantine business sucks! I’ve got too much time on my hands.

Here is an option to use workperiods instead of Ticket Date and Date:

```
{REPORT TICKET DETAILS:W.Id:(Ticket.Id={TICKET ID})} Equals {WORKPERIOD ID}

```

This will use the workperiod id of the ticket against the current workperiod. This would work if open past midnight and not using virtual workperiods (I think). However, if a workperiod was forgotten to end the previous day, it would be possible to re-open the ticket the following day.

---

<div class="post-metadata">

**Author:** ![JTRTech](https://forum.sambapos.com/user_avatar/forum.sambapos.com/jtrtech/32/21270_2.png) [@JTRTech](https://forum.sambapos.com/u/JTRTech)\
**Post date:** [April 27, 2020, 11:46pm UTC](https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063/11 "2020-04-27T23:46:34Z")

</div>

Yes however the ticket would still be in the current work period so wouldn’t cause already reported period figure changes. Yes you have have already printed (a x type read) however the running total would make it still a ‘live’ ticket.

---

<div class="post-metadata">

**Author:** ![Memo](https://forum.sambapos.com/user_avatar/forum.sambapos.com/memo/32/55443_2.png) [@Memo](https://forum.sambapos.com/u/Memo)\
**Post date:** [April 28, 2020, 3:46am UTC](https://forum.sambapos.com/t/stop-ticket-re-opening-after-wp-closed/22063/12 "2020-04-28T03:46:15Z")

</div>

> [@Bob\_be](#):
>
> This quarantine business sucks! I’ve got too much time on my hands.
> 
> Here is an option to use workperiods instead of Ticket Date and Date:
> 
> ```auto
> {REPORT TICKET DETAILS:W.Id:(Ticket.Id={TICKET ID})} Equals {WORKPERIOD ID}
> 
> ```
> 
> This will use the workperiod id of the ticket against the current workperiod. This would work if open past midnight and not using virtual workperiods (I think). However, if a workperiod was forgotten to end the previous day, it would be possible to re-open the ticket the following day.

Add `'{SETTING:ISCURRENTWORKPERIODOPEN}' == 'TRUE'` to the constraint to Execute Automation Command and it works. A simpler solution - love it!

Without that constraint I was able to reopen and resettle a ticket with no open work period. I’m actually quite curious what that’ll do to reports.
