Search code examples
oracle-apex

How can I implement my associative entity in Oracle Apex?


I have an associative Entity for which I can't understand how to implement it's interface in Oracle Apex it just doesn't cross my minds and I would love if you guys could help me.

Here's my case andn what I want to do: model

The clients log in the application. They can create an order. Everything is almost automatic in the order tables (COMMANDES), the reference is a sequence number, the order_date (date_commande) is an automatic SYSTIMESTAMP, .. etc.

I want the user to be able to CREATE an Order, or at least initialize it, in which he will be able to add order lines (LIGNESCOMMANDES). These order lines must refer to Beers (BIERES), and an order (the previous one initialized) and a quantity for the number of beers.

I want the user to be able to do all of this : create / initialize an order, add order lines with beers and quantity, and the price (PRIX) column on the order to be computed based on the quantity of beers and their prices in their table.

I've already tried using a Wizard, Interactive Grid, Master Details and the last one is actually my most "efficient", but I cannot make it work properly.

Do you guys have an idea on how I could do it in the most right way ? I'm open to all suggestions.

Thank you for reading,

Thomas


Solution

  • I'd suggest creating a pl/sql procedure (in a package) to handle the logic/work. Client creates an an order. At that point you have the client id. Client selects a number of items (beers). Then saves. When form is saved the order is created (returning into clause will give you order_id) items (selected beers) can be added to the order (lignes commandes). So your pl/sql procedure would take clients.id and an array of bieres.id as input. With those input parameters it can create an order and add the items to the order (one record in commandes, one record per bieres.id in ligne_commandes). This can all be done as anonymous pl/sql blocks in page processing but honestly, it makes more sense to put this code in a package.

    In the UI I would go for a form that has the order header info (or just the client as a select list) and an interactive grid for the line details (type of beer and quantity). Use a dynamic action to calculate the line price and the total sum.