# Arbitrary Counter

**URL:** <https://forum.sambapos.com/t/arbitrary-counter/11671>\
**Category:** V5 Question\
**Created:** [July 15, 2016, 4:45am UTC](https://forum.sambapos.com/t/arbitrary-counter/11671 "2016-07-15T04:45:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![digithai](https://forum.sambapos.com/letter_avatar_proxy/v4/letter/d/59ef9b/32.png) [@digithai](https://forum.sambapos.com/u/digithai)\
**Post date:** [July 15, 2016, 4:45am UTC](https://forum.sambapos.com/t/arbitrary-counter/11671/1 "2016-07-15T04:45:30Z")

</div>

I dont know if anyone has ever implemented this, but here is the concept/situation:

- Every ticket has an associated bill.
- Some customers request a tax invoice as well, so we print that for them on request.
- Every TAX invoice needs to have a serial number.
- Since not every bill is associated with a TAX invoice, the number of bills will be different from the number of tax invoices.
- So is there a way to run a counter on the TAX Invoices printed so that they have a valid count?

I was thinking of defining an Entity for this, and insert a new row everytime a new tax invoice is printed.  
But to do that, how do i define an auto-increment custom field? And, how do i get the new entity created and add that to my ticket ?

---

<div class="post-metadata">

**Author:** ![QMcKay](https://forum.sambapos.com/user_avatar/forum.sambapos.com/qmckay/32/27925_2.png) [@QMcKay](https://forum.sambapos.com/u/QMcKay)\
**Post date:** [July 15, 2016, 5:20am UTC](https://forum.sambapos.com/t/arbitrary-counter/11671/2 "2016-07-15T05:20:21Z")

</div>

You could use the Action of `Update Program Setting` with `Is Local` set to false. Then the value is stored in the Database.

When you print a Tax Invoice, you increment the Program Setting.

Then if you want to create an Entity use:

`Create Entity` Action

Then if you want to add the Entity to the Ticket, use:

`Change Ticket Entity` Action. You can add an Entity with that instead of changing an Entity.

So in the end, you might have an Automation Command to print the Tax Invoice. When that is clicked:

Increment the Program Setting.  
Create Entity  
Add Entity to Ticket  
Print the Invoice

---

<div class="post-metadata">

**Author:** ![digithai](https://forum.sambapos.com/letter_avatar_proxy/v4/letter/d/59ef9b/32.png) [@digithai](https://forum.sambapos.com/u/digithai)\
**Post date:** [July 15, 2016, 5:30am UTC](https://forum.sambapos.com/t/arbitrary-counter/11671/3 "2016-07-15T05:30:03Z")

</div>

Kool! that makes sense!  
How do i retrieve the value of this program setting to actually print this number on my Invoice?

---

<div class="post-metadata">

**Author:** ![QMcKay](https://forum.sambapos.com/user_avatar/forum.sambapos.com/qmckay/32/27925_2.png) [@QMcKay](https://forum.sambapos.com/u/QMcKay)\
**Post date:** [July 15, 2016, 5:51am UTC](https://forum.sambapos.com/t/arbitrary-counter/11671/4 "2016-07-15T05:51:17Z")

</div>

Like this, using this tag:

```auto
{SETTING:settingName}

```

So if you have a Program Setting that you called `Tax Invoice Number`, you would use this in your Template:

```auto
{SETTING:Tax Invoice Number}

```

In the case assigning an Entity, of for example an Entity Type called `Tax Invoice Numbers`, this would work better, since the Entity will have been attached to the Ticket:

```auto
{ENTITY NAME:Tax Invoice Numbers}

```

That assumes the Name of the Entity is the Invoice Number.

---

<div class="post-metadata">

**Author:** ![digithai](https://forum.sambapos.com/letter_avatar_proxy/v4/letter/d/59ef9b/32.png) [@digithai](https://forum.sambapos.com/u/digithai)\
**Post date:** [July 15, 2016, 9:40am UTC](https://forum.sambapos.com/t/arbitrary-counter/11671/5 "2016-07-15T09:40:11Z")

</div>

This was perfect!  
dont even need to declare an entity or anything… i just needed a running number on my tax invoices. and the {SETTING; TAX INV NUMBER} did the whole trick.

Cheers!
