|
|
|
@ -986,7 +986,9 @@ declare
|
|
|
|
|
_item_uuids uuid[];
|
|
|
|
|
_cart_uuid uuid;
|
|
|
|
|
_item_uuid uuid;
|
|
|
|
|
_item_count integer;
|
|
|
|
|
_cart_item_count integer;
|
|
|
|
|
_available_item_count integer;
|
|
|
|
|
_item_availability_date timestamptz;
|
|
|
|
|
_stockchange_uuid uuid;
|
|
|
|
|
begin
|
|
|
|
|
-- Get cart uuid (and check completed)
|
|
|
|
@ -1009,31 +1011,65 @@ begin
|
|
|
|
|
|
|
|
|
|
-- Make stock-change record for each item
|
|
|
|
|
foreach _item_uuid in array _item_uuids loop
|
|
|
|
|
select cart_item_count into _item_count from sos."cart_item"
|
|
|
|
|
-- Get cart and item info
|
|
|
|
|
select cart_item_count into _cart_item_count from sos."cart_item"
|
|
|
|
|
where cart_item_cart_uuid = _cart_uuid
|
|
|
|
|
and cart_item_item_uuid = _item_uuid;
|
|
|
|
|
|
|
|
|
|
insert into sos."item_stockchange" (
|
|
|
|
|
stockchange_type,
|
|
|
|
|
stockchange_item_uuid,
|
|
|
|
|
stockchange_change,
|
|
|
|
|
stockchange_direction
|
|
|
|
|
) values (
|
|
|
|
|
'purchase',
|
|
|
|
|
_item_uuid,
|
|
|
|
|
_item_count,
|
|
|
|
|
'subtracted'
|
|
|
|
|
) returning stockchange_uuid into _stockchange_uuid;
|
|
|
|
|
|
|
|
|
|
insert into sos."item_stockchange_purchase" (
|
|
|
|
|
stockchange_uuid,
|
|
|
|
|
stockchange_type,
|
|
|
|
|
stockchange_transaction_uuid
|
|
|
|
|
) values (
|
|
|
|
|
_stockchange_uuid,
|
|
|
|
|
'purchase',
|
|
|
|
|
_transaction_uuid
|
|
|
|
|
);
|
|
|
|
|
select
|
|
|
|
|
item_number_in_stock, item_preorder_availability_date
|
|
|
|
|
into _available_item_count, _item_availability_date
|
|
|
|
|
from sos.v_item
|
|
|
|
|
where item_uuid = _item_uuid;
|
|
|
|
|
|
|
|
|
|
-- Pre-order stockchange
|
|
|
|
|
if _cart_item_count > _available_item_count and _item_availability_date is not null then
|
|
|
|
|
insert into sos."item_stockchange" (
|
|
|
|
|
stockchange_type,
|
|
|
|
|
stockchange_item_uuid,
|
|
|
|
|
stockchange_change,
|
|
|
|
|
stockchange_direction
|
|
|
|
|
) values (
|
|
|
|
|
'preorder',
|
|
|
|
|
_item_uuid,
|
|
|
|
|
_cart_item_count,
|
|
|
|
|
'subtracted'
|
|
|
|
|
) returning stockchange_uuid into _stockchange_uuid;
|
|
|
|
|
|
|
|
|
|
insert into sos."item_stockchange_preorder" (
|
|
|
|
|
stockchange_uuid,
|
|
|
|
|
stockchange_type,
|
|
|
|
|
stockchange_transaction_uuid,
|
|
|
|
|
stockchange_preorder_estimated_fulfill_date
|
|
|
|
|
) values (
|
|
|
|
|
_stockchange_uuid,
|
|
|
|
|
'preorder',
|
|
|
|
|
_transaction_uuid,
|
|
|
|
|
_item_availability_date
|
|
|
|
|
);
|
|
|
|
|
else -- Non-preorder stockchange
|
|
|
|
|
insert into sos."item_stockchange" (
|
|
|
|
|
stockchange_type,
|
|
|
|
|
stockchange_item_uuid,
|
|
|
|
|
stockchange_change,
|
|
|
|
|
stockchange_direction
|
|
|
|
|
) values (
|
|
|
|
|
'purchase',
|
|
|
|
|
_item_uuid,
|
|
|
|
|
_cart_item_count,
|
|
|
|
|
'subtracted'
|
|
|
|
|
) returning stockchange_uuid into _stockchange_uuid;
|
|
|
|
|
|
|
|
|
|
insert into sos."item_stockchange_purchase" (
|
|
|
|
|
stockchange_uuid,
|
|
|
|
|
stockchange_type,
|
|
|
|
|
stockchange_transaction_uuid
|
|
|
|
|
) values (
|
|
|
|
|
_stockchange_uuid,
|
|
|
|
|
'purchase',
|
|
|
|
|
_transaction_uuid
|
|
|
|
|
);
|
|
|
|
|
end if;
|
|
|
|
|
end loop;
|
|
|
|
|
|
|
|
|
|
return query select * from sos.v_item where item_uuid = any(_item_uuids);
|
|
|
|
|