Stop transaction if quantity is 0

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
rrahmad
Posts: 8
Joined: 2019-10-05 15:14

Stop transaction if quantity is 0

Post by rrahmad » 2019-12-12 05:55

hi
regarding sample project
https://bigprof.com/appgini/application ... ry-manager
how do you stop transaction if quantity is 0. thanks.

lectura
Posts: 28
Joined: 2015-01-10 13:29

Re: Stop transaction if quantity is 0

Post by lectura » 2019-12-21 05:33

Am also waiting for someone to implement the same.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Stop transaction if quantity is 0

Post by jsetzer » 2019-12-21 09:42

I'm not sure if I got your point. If you want to cancel a transaction before calculation/update of balance, you can modify both before_insert and before_update hook functions.

Replace return TRUE; in transactions_before_...-hooks like this:

Code: Select all

// file: hooks/transactions.php
// [...]
function transactions_before_insert(&$data, $memberInfo, &$args)
{
	return $data["quantity"] > 0;
}
// [...]
function transactions_before_update(&$data, $memberInfo, &$args)
{
	return $data["quantity"] > 0;
}
// [...]
Hope this helps!
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Stop transaction if quantity is 0

Post by jsetzer » 2019-12-21 10:00

There is also a client-side (browser) way to cancel submit if quantity is zero (or less than zero).

By default quantity is a decimal(10,2) field in OIM demo app. Depending on your specific scenario, "greater than zero" can be interpreted as ">= 0.01" or as ">= 1".

Possible solution for Quantity >= 1

Code: Select all

function transactions_dv($selectedID, $memberInfo, &$html, &$args)
{
	$html .= '<script>jQuery("#quantity").attr("type","number").attr("min","1").attr("step","1");</script>';
}
Possible solution for Quantity >= 0.01

Code: Select all

function transactions_dv($selectedID, $memberInfo, &$html, &$args)
{
	$html .= '<script>jQuery("#quantity").attr("type","number").attr("min","0.01").attr("step","0.01");</script>';
}
bbqlMWbMXL.gif
bbqlMWbMXL.gif (172.05 KiB) Viewed 6166 times
I recommend combining both methods (client-side Javascript as shown in this post AND server-side PHP hook as shown in previous post).

Best,
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

lectura
Posts: 28
Joined: 2015-01-10 13:29

Re: Stop transaction if quantity is 0

Post by lectura » 2019-12-25 12:32

The challenge we are facing is:lets incoming is 100.
So outgoing will reduce the 100 until its negative value. So we wanted when the stored value has reached 0 then any antry for outgoing should be rejected. As there is mo stock.
Both outgoing and incoming are working on same value in this case our 100.
If in our case there was code to check if therecis value to before outgoing it will solve the problem.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Stop transaction if quantity is 0

Post by onoehring » 2019-12-26 09:39

Hi Lectura,

I do not understand what you mean ... didn't Jan suggest two different possible solutions for your problem?
If you need to do some background checking on your data you might take his first (/hooks) approach. This enables you to see if there is still enough in stock to deduct another 100 (in your example). If no, simply cancel the update of the record.
Take a look a my custom error message here (on how you could inform the user): viewtopic.php?f=7&t=1740&p=10871#p10906


Olaf

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Stop transaction if quantity is 0

Post by jsetzer » 2019-12-26 09:59

Hi Lectura,

you will have to modify function update_balances($data) in hooks/transactions.php according to your needs.

If, for example, quantity on stock is 30 and order-quantity in transaction is 100, there are at least three different ways which immediately came into my mind how to handle this scenario:
  1. completely reject transaction (because it cannot be fulfilled completely) and keep it in status "open"

    or
  2. decrease transaction quantity by 70 pcs, then fulfill the remaining 30 pcs of that transactions, reduce stock by 30 pcs to 0 and notify user about the remaining 70 not-delivered pieces

    or
  3. (recommended) split (=duplicate) the one transaction into two identical transactions with different quantities (30 pcs and 70 pcs), then fulfill the 1st transaction (30pcs) and keep the 2nd transaction (70pcs) in status "pending". Notify user. Track quantity on stock until "pending" transactions can be fulfilled.
There is no right or wrong and there are many more possible solutions. So it really depends on your specific needs and - as mentioned above - you will have to modifiy that function according to your requirements or at least specify in detail what exactly you need.

Hope this helps understanding the problem and why there is not a single solution but multiple possible solutions.

Best,
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

lectura
Posts: 28
Joined: 2015-01-10 13:29

Re: Stop transaction if quantity is 0

Post by lectura » 2019-12-31 07:18

Wonderful explanation Jan.
Option (a) is the best. Completely reject the transaction. Now coding it is the next problem. Any guide?

Post Reply