hi
regarding sample project
https://bigprof.com/appgini/application ... ry-manager
how do you stop transaction if quantity is 0. thanks.
Stop transaction if quantity is 0
Re: Stop transaction if quantity is 0
Am also waiting for someone to implement the same.
Re: Stop transaction if quantity is 0
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:
Hope this helps!
Jan
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;
}
// [...]
Jan
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<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 readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: Stop transaction if quantity is 0
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
Possible solution for Quantity >= 0.01
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
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>';
}
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>';
}
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
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<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 readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: Stop transaction if quantity is 0
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.
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.
Re: Stop transaction if quantity is 0
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
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
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
Re: Stop transaction if quantity is 0
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:
Hope this helps understanding the problem and why there is not a single solution but multiple possible solutions.
Best,
Jan
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:
- completely reject transaction (because it cannot be fulfilled completely) and keep it in status "open"
or - 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 - (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.
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
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<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 readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: Stop transaction if quantity is 0
Wonderful explanation Jan.
Option (a) is the best. Completely reject the transaction. Now coding it is the next problem. Any guide?
Option (a) is the best. Completely reject the transaction. Now coding it is the next problem. Any guide?