# Permanent Price Change through Automation

**URL:** <https://forum.sambapos.com/t/permanent-price-change-through-automation/11003>\
**Category:** V5 Question\
**Created:** [May 29, 2016, 7:26am UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003 "2016-05-29T07:26:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pauln](https://forum.sambapos.com/user_avatar/forum.sambapos.com/pauln/32/12698_2.png) [@pauln](https://forum.sambapos.com/u/pauln)\
**Post date:** [May 29, 2016, 7:26am UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/1 "2016-05-29T07:26:31Z")

</div>

Hello All

Has anyone had a crack at effecting a User permanent price change through automation of the fly? I would like to be able to update any price cell listed below 🙂

 ![](https://forum.sambapos.com/uploads/default/original/3X/0/c/0c095f15e91028384ef9aee5b25b7c4ce34f06d4.JPG)

**Permanent Price Changes** are a common feature in POS systems and I have been asked to implement such a function for “Beer of Week”.

@QMcKay would you be able to shout me the “UPDATE” code for any cell above? You may have done this in your PHP Inventory Import Add On… 😊

So Far I have this:

 ![](https://forum.sambapos.com/uploads/default/original/3X/9/d/9d7bd0b73550ee892384763083dd5b16a390eced.JPG)

I was thinking to use {SETTING:x} to capture “Before Price” but I know the RULE Evaluation can get a bit funky! So Maybe use a SQL Fetch Price and compare to {PRICE} after UPATE ORDER - [:Price] has been performed.

If they are different then SQL UPDATE on User Prompt Confirmation?

---

<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:** [May 29, 2016, 7:44am UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/2 "2016-05-29T07:44:19Z")

</div>

You will need to make a decision, because if the Price is not set for a Portion/PriceTag, then you will need an INSERT statement.

If the Portion/PriceTag is already set, this UPDATE statement will do the trick. Notice the special case - `(REG)`, commented out - that needs to be used when you are updating the “regular” price …

```sql
--
-- set some vars to make this dynamic
--
declare @priceTagExists int = 0
--declare @priceTag varchar(50) = '(REG)'
declare @priceTag varchar(50) = 'VIP1'
declare @product varchar(50) = 'ACCOUNT PAYMENT'
declare @portion varchar(50) = 'Normal'
declare @price varchar(50) = '100.00'

--
-- determine if the Portion/PriceTag Exists
--
SELECT @priceTagExists = count(1)
FROM [MenuItemPrices] ppr
JOIN [MenuItemPortions] po on po.[Id] = ppr.[MenuItemPortionId]
JOIN [MenuItems] pr on pr.[Id] = po.[MenuItemId]
WHERE 1=1
AND pr.[Name] = @product
AND po.[Name] = @portion
AND isnull(ppr.[PriceTag],'(REG)') = @priceTag

--
-- if it does NOT exist, then INSERT it
--
IF @priceTagExists=0
BEGIN
INSERT INTO [MenuItemPrices] ([MenuItemPortionId],[PriceTag],[Price]) VALUES (
 (SELECT po.[Id] FROM [MenuItemPortions] po JOIN [MenuItems] pr on pr.[Id] = po.[MenuItemId] WHERE pr.[Name] = @product and po.[Name] = @portion)
,(SELECT pd.[Name] FROM [MenuItemPriceDefinitions] pd WHERE pd.[PriceTag] = @priceTag)
,@price
)
END

--
-- if it DOES exist, UPDATE it
--
IF @priceTagExists>0
BEGIN
UPDATE ppr SET
ppr.[Price] = @price
FROM [MenuItemPrices] ppr
JOIN [MenuItemPortions] po on po.[Id] = ppr.[MenuItemPortionId]
JOIN [MenuItems] pr on pr.[Id] = po.[MenuItemId]
WHERE 1=1
AND pr.[Name] = @product
AND po.[Name] = @portion
AND isnull(ppr.[PriceTag],'(REG)') = @priceTag
END

--
-- let's see our Results
--
SELECT 
 pr.[Name] as [Product]
,po.[Name] as [Portion]
,isnull([PriceTag],'(REG)') as [PriceTag]
,[Price]
FROM [MenuItemPrices] ppr
JOIN [MenuItemPortions] po on po.[Id] = ppr.[MenuItemPortionId]
JOIN [MenuItems] pr on pr.[Id] = po.[MenuItemId]
WHERE pr.[Name] = @product and po.[Name] = @portion
ORDER BY pr.[Name],po.[Id]

```

---

<div class="post-metadata">

**Author:** ![pauln](https://forum.sambapos.com/user_avatar/forum.sambapos.com/pauln/32/12698_2.png) [@pauln](https://forum.sambapos.com/u/pauln)\
**Post date:** [May 29, 2016, 11:43am UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/3 "2016-05-29T11:43:30Z")

</div>

OMG Q! - that’s why you ask the people who know 😁 I have said it before so will say it again, your SQL skills are top notch.

Do not take that other job, please as there will be a thousand jealous bleeding hearts on this forum 😨

---

<div class="post-metadata">

**Author:** ![emre](https://forum.sambapos.com/user_avatar/forum.sambapos.com/emre/32/39073_2.png) [@emre](https://forum.sambapos.com/u/emre)\
**Post date:** [May 29, 2016, 12:17pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/4 "2016-05-29T12:17:04Z")

</div>

> [@pauln](#):
>
> Do not take that other job

Wait… What other job ??

---

<div class="post-metadata">

**Author:** ![pauln](https://forum.sambapos.com/user_avatar/forum.sambapos.com/pauln/32/12698_2.png) [@pauln](https://forum.sambapos.com/u/pauln)\
**Post date:** [May 29, 2016, 12:18pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/5 "2016-05-29T12:18:41Z")

</div>

> [@SambaPOS 5 Bulk Product and Inventory Importer](https://forum.sambapos.com/t/sambapos-5-bulk-product-and-inventory-importer/10809/40):
>
> Good on ya! I have recently been approached to possibly become the Tech for a new POS “company” here. Not sure I want to have the extra work though, lol. Between my 2 Venues, Beta Testing, Forum support, etc, it really cuts down on my “social” time stuck_out_tongue_winking_eye

It just cannot happen 😭

---

<div class="post-metadata">

**Author:** ![pauln](https://forum.sambapos.com/user_avatar/forum.sambapos.com/pauln/32/12698_2.png) [@pauln](https://forum.sambapos.com/u/pauln)\
**Post date:** [May 29, 2016, 1:03pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/6 "2016-05-29T13:03:49Z")

</div>

Sorry @emre

I just cannot seem to trap current {PRICE TAG} for an Order as this is the last ingredient needed to update a Price:

 ![](https://forum.sambapos.com/uploads/default/original/3X/f/c/fcd0fe3c13d1dbeb9cacae0dc68a08b938301533.JPG)

Show Dialogue:

 ![](https://forum.sambapos.com/uploads/default/original/3X/7/4/74b08a55470b4f617b944f2fd642867c881e62cd.JPG)

Should be simple right?

Also I will need to trim {NAME} to remove the PORTION suffix.

---

<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:** [May 29, 2016, 1:14pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/7 "2016-05-29T13:14:44Z")

</div>

There is a tag for product name without portion.  
Use it on my template to override Name.Portion to have a space rather than the point.  
Not at PC but it will be something like product name or item name.  
Check the ticket template tag list, it’s on there somewhere.

---

<div class="post-metadata">

**Author:** ![pauln](https://forum.sambapos.com/user_avatar/forum.sambapos.com/pauln/32/12698_2.png) [@pauln](https://forum.sambapos.com/u/pauln)\
**Post date:** [May 29, 2016, 1:19pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/8 "2016-05-29T13:19:14Z")

</div>

Cool thanks JTRTech - `{PRODUCT NAME}` does the trick. Just need the last piece of the puzzle now **“Price Definition” used for an Selected Order Line?**

---

<div class="post-metadata">

**Author:** ![pauln](https://forum.sambapos.com/user_avatar/forum.sambapos.com/pauln/32/12698_2.png) [@pauln](https://forum.sambapos.com/u/pauln)\
**Post date:** [May 29, 2016, 1:34pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/9 "2016-05-29T13:34:20Z")

</div>

#oh no a conundrum!

So here is the thing {PRICE TAG} is working but the Update Order ACTION is effecting the change of Price of the DEFAULT Price as no Price Tag is passed! The resultant new Price for the Order Line will be listed as a Regular Price.

In this case {PRICE TAG} = Null.

---

<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:** [May 29, 2016, 6:07pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/10 "2016-05-29T18:07:57Z")

</div>

I think I remember reading somewhere that `{PRICE TAG}` is broken. What version are you running?

---

<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:** [May 29, 2016, 6:18pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/11 "2016-05-29T18:18:11Z")

</div>

> [@QMcKay](#):
>
> remember reading somewhere that {PRICE TAG} is broken.

I did almost sugest that, I remember that being said and sure emre said fixed for next release, which release was next after that am not sure LOL

---

<div class="post-metadata">

**Author:** ![pauln](https://forum.sambapos.com/user_avatar/forum.sambapos.com/pauln/32/12698_2.png) [@pauln](https://forum.sambapos.com/u/pauln)\
**Post date:** [May 29, 2016, 11:24pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/12 "2016-05-29T23:24:59Z")

</div>

Good Morning Q - yep running the latest beta version V5.1.60.

---

<div class="post-metadata">

**Author:** ![pauln](https://forum.sambapos.com/user_avatar/forum.sambapos.com/pauln/32/12698_2.png) [@pauln](https://forum.sambapos.com/u/pauln)\
**Post date:** [May 30, 2016, 2:59pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/13 "2016-05-30T14:59:59Z")

</div>

Hi @QMcKay

Can you cast your eye over the generated SQL - I think the last bit is wrong? Should it be:  
`AND isnull(ppr.[PriceTag],'(REG)',[PriceTag]) = 'Happy Hour'`  
Are we missing the `,[PriceTag]`

![](https://forum.sambapos.com/uploads/default/original/3X/f/d/fd0b4126c86ac75a0ac51217ec04e8f706e63a24.JPG)

**[EDIT]**  
Wait a moment - HOLY MOLLY - writing Normal Prices…

Oh no the “Old Cache” issue, I was worried about that 😟

---

<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:** [May 30, 2016, 3:27pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/14 "2016-05-30T15:27:02Z")

</div>

No, it looks correct. It should be, as it is:

```sql
isnull(ppr.[PriceTag],'(REG)') = 'whatever'

```

The reason we do that is for when we want to update the Regular Price (the price that has no PriceTag). By using the `isnull(field,'replacement')` then we don’t need to change the code for the special case of the Regular price. If we did not do that, then we would need to change it to the following, but only for the special case of the Regular price:

```auto
[PriceTag] is null

```

Instead, we match our special case to `(REG)` and we don’t need to change our code:

```sql
isnull(ppr.[PriceTag],'(REG)') = '(REG)' -- the price has no PriceTag
isnull(ppr.[PriceTag],'(REG)') = 'VIP1' -- the price has PriceTag of VIP1

```

ISNULL is similar to `COALESCE(field,'replacement')`

---

<div class="post-metadata">

**Author:** ![pauln](https://forum.sambapos.com/user_avatar/forum.sambapos.com/pauln/32/12698_2.png) [@pauln](https://forum.sambapos.com/u/pauln)\
**Post date:** [May 30, 2016, 3:35pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/15 "2016-05-30T15:35:00Z")

</div>

Hey thanks Q! - guess what I (we) have it working, “the unworkable solution” actually working. The only thing I am having an issue with is the Cache.

When the price is updated, I do Refresh Cache ACTION but this only takes effect when I cancel the order and close ticket. What actually happens then is the Menus go blank? Then when I reclick Department all comes back and the new price is available in any Portions and Price Tag.

As we are in a Ticket, ummmm…

---

<div class="post-metadata">

**Author:** ![pauln](https://forum.sambapos.com/user_avatar/forum.sambapos.com/pauln/32/12698_2.png) [@pauln](https://forum.sambapos.com/u/pauln)\
**Post date:** [May 30, 2016, 3:56pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/16 "2016-05-30T15:56:16Z")

</div>

Hey @emre

Well the **permanent pricing workflow** is operating well with 1 small hitch - the “old cache” scenario. From the GIF below you can see the price is written to the DBO using script but the Menu Pricing Cache is not refreshed until I close the Ticket and I guess Navigate.

 ![](https://forum.sambapos.com/uploads/default/original/3X/4/f/4f338d56aad4db66ee402621f7e5e7ed41e1cfa2.gif)

I know you would have special controls here to ensure SambaPOS works fast and efficient.  
So what can you suggest?

PS: The Menu goes blank on its own, I assume due to the Refresh Cache Action.

**[EDIT]**  
Well another midnight finish 😫  
Happy to accept any suggestions over night. I am thinking of an no so elegant flow of placing the ticket on hold (this may submit an old price?), switching Menus or Navigate or something, reload Ticket. Sort of clunky…

---

<div class="post-metadata">

**Author:** ![emre](https://forum.sambapos.com/user_avatar/forum.sambapos.com/emre/32/39073_2.png) [@emre](https://forum.sambapos.com/u/emre)\
**Post date:** [May 30, 2016, 4:06pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/17 "2016-05-30T16:06:53Z")

</div>

Do you know you need to reset cache on all terminals if it is a permanent change 😉

---

<div class="post-metadata">

**Author:** ![pauln](https://forum.sambapos.com/user_avatar/forum.sambapos.com/pauln/32/12698_2.png) [@pauln](https://forum.sambapos.com/u/pauln)\
**Post date:** [May 30, 2016, 4:08pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/18 "2016-05-30T16:08:52Z")

</div>

That is a good point @emre!  
But for now I have the problem that the Cache Reset **does not do the Job** as we are in middle of a Ticket? I do not know how to get around that one…

Anybody feel free to offer suggestions while I pull the remaining hair from my head overnight.

Nope switching Menus back and forth will not do it after a Refresh Cache.

---

<div class="post-metadata">

**Author:** ![emre](https://forum.sambapos.com/user_avatar/forum.sambapos.com/emre/32/39073_2.png) [@emre](https://forum.sambapos.com/u/emre)\
**Post date:** [May 30, 2016, 8:37pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/19 "2016-05-30T20:37:45Z")

</div>

On next update `mutation m{postResetProductCacheMessage{id}}` API command will reset product prices inside tickets on all terminals.

Also `updateProductPrice` mutation will include notifyClients parameter to do that automatically after updating a product price.

PS: Refresh cache won’t work inside tickets and setups a late trigger that works after closing ticket as refresh cache action clears entire cache and that may create issues with ticket’s state data.

---

<div class="post-metadata">

**Author:** ![pauln](https://forum.sambapos.com/user_avatar/forum.sambapos.com/pauln/32/12698_2.png) [@pauln](https://forum.sambapos.com/u/pauln)\
**Post date:** [May 30, 2016, 11:02pm UTC](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003/20 "2016-05-30T23:02:55Z")

</div>

Ok thanks @emre.

> [@emre](#):
>
> PS: Refresh cache won’t work inside tickets and setups a late trigger that works after closing ticket as refresh cache action clears entire cache and that may create issues with ticket’s state data.

Are you referring to what I am trying now? If Yes, no problems I have already removed all that flow late last night (morning). The message to the user now says _“WARNING: Please log off/on each terminal to refresh the new prices”._

[Next page](https://forum.sambapos.com/t/permanent-price-change-through-automation/11003.md?page=2)
