I'm trying to create POS system using oracle apex like the one at supermarkets, my issue is when the user scan the same item twice I want the application to increase it's quantity by '1' not to duplicate the record in my database, so I have write the below code but it doesn't work the way I want and it keep duplicating the item record on database.
declare v_count number;
begin
select COUNT(*) co
into v_count
from POS_TRANS_DETAIL
where PTM_ID = :P21_MASTER_ID and serial_number = :P21_SERIAL_NUMBER ;
if v_count >= 1 then
update POS_TRANS_DETAIL
set QUANTITY = v_count +1
where PTM_ID = :P21_MASTER_ID and serial_number = :P21_SERIAL_NUMBER ;
end if;
EXCEPTION
WHEN no_data_found THEN
begin
insert into POS_TRANS_DETAIL values (
TRANS_DETAIL_ID.nextval,
:P21_PTM_ID,
:P21_SERIAL_NUMBER,
:P21_COST_PRICE,
:P21_QUANTITY,
);
end;
end;
The first statement is for getting any duplicate serial number in the same receipt number (PTM_ID) and to store number of duplicate record on v_count, using the if statement I'm making sure that v_count has a value and then applying the update for quantity column, and in the exception section I'm handling new item insertion when no row return from the select statement which mean that the item didn't added before for the same receipt
I'm placing this code on a dynamic action fired when the user add new item.