Projects:Intercompanyinvoicing/Technical Documentation
The development of the module has been separated in three parts. First one consist on creating all the necessary fields and data. The other two consist on developing the necessary procedures to generate the matching orders and invoices.
Contents |
Required new fields
Document Type window
- New is intercompany checkbox in Document Definition tab, EM_INTERCO_IS_INTERCOMPANY char(1) in C_DOCTYPE table.
- New Inter-company Relations tab child of Document Definition. This tab has the usual fields, a Source Organization combo drop-down, a Target Organization combo drop-down with all the organizations and Target Document Type drop-down with the available document types for the target organization.
- New INTERCO_INTERCOMPANY_RELATIONS table for the tab. Columns:
- INTERCO_MATCHING_DOCUMENT_ID as primary key, CREATED, CREATEDBY, UPDATED, UPDATEDBY, AD_ORG_ID, AD_CLIENT_ID and ISACTIVE as usual.
- C_DOCTYPE_ID as a parent key, foreign key of C_DOCTYPE table.
- C_DOCTYPETARGET_ID, foreign key of C_DOCTYPE table.
- AD_ORGTARGET_ID, foreign key of AD_ORG table.
- AD_ORGSOURCE_ID, foreign key of AD_ORG table.
Purchase and Sales Order window
- New Original Order read only field. EM_INTERCO_ORIGINAL_ORDER_ID in C_ORDER table. Foreign key of C_ORDER table, use the search type reference. Notice that this field will only be visible if its value is not null. the display logic has to be set according to this.
- New trigger in C_Order table on inserting and updating. This trigger has to check that, if the C_DOCTYPETARGET_ID is of a C_DOCTYPE that has the IS_INTERCOMPANY flag set to Y:
- The business partner C_BPARTNER_ID is mapped to one (and only one) organization.
- The organization is mapped to a business partner.
Purchase and Sales Invoice window
- New Original Invoice read only field. EM_INTERCO_ORIGINAL_INVOICE_ID in C_INVOICE table. Foreign key of C_INVOICE table, use the search type reference. Notice that this field will only be visible if its value is not null. the display logic has to be set according to this.
- New trigger in C_Invoice table on inserting and updating. This trigger has to check that, if the C_DOCTYPETARGET_ID is of a C_DOCTYPE that has the IS_INTERCOMPANY flag set to Y:
- The business partner C_BPARTNER_ID is mapped to one (and only one) organization.
- The organization is mapped to a business partner.
Intercompany Orders
Create a new database procedure called INTERCO_CREATE_ORDER. This database procedure will be inserted in the C_Order_Post - Finish Process Extension Point. This way it will be called at the end of c_order_post. As for that, a new record has to be created in:
- Application Dictionary | Setup | Extension Point. Select the record C_Order_Post - Finish Process and add a child record with the name of the procedure.
The database procedure has the following paramenters:
- AD_EP_Instance VARCHAR2
The database procedure will retrieve the following values trough ad_ep_instance_param table based on the given ad_ep_instance:
- In Parameters:
- Record_ID (it is the C_Order_ID being processed)
- DocAction
- User
- Out Parameters:
- Message
- Result
Procedure
This procedure has to create a new order when:
- The c_doctypetarget_id of the C_Order is of a c_doctype that has the em_interco_is_intercompany set to Y
- The order hasn't been generated. That is, EM_INTERCO_ORIGINAL_ORDER_ID is null
- The order is being completed (v_docaction = "CO").
Once the order is created it has to be completed calling back the C_ORDER_POST procedure.
The only actions allowed for intercompany orders are, complete when is in draft status, unlock if there has been an error in previous processing and close when it is in completed status. Any other action has to raise an exception.
RAISE_APPLICATION_ERROR(-20000, '@ActionNotSupported@');
If the process fails it has to rollback the whole process, including the original order. This can be done raising an exception, doing a RAISE_APPLICATION_ERROR with an user friendly message.
Intercompany Invoices
Create a new database procedure called INTERCO_CREATE_INVOICE. This database procedure will be inserted in the C_Invoice_Post - Finish Process Extension Point. This way it will be called at the end of c_invoice_post. As for that, a new record has to be created in:
- Application Dictionary | Setup | Extension Point. Select the record C_Invoice_Post - Finish Process and add a child record with the name of the procedure.
The database procedure has the following paramenters:
- AD_EP_Instance VARCHAR2
The database procedure will retrieve the following values trough ad_ep_instance_param table based on the given ad_ep_instance:
- In Parameters:
- Record_ID (it is the C_Invoice_ID being processed)
- DocAction
- User
- Out Parameters:
- Message
- Result
Procedure
This procedure has to create a new invoice when:
- The c_doctypetarget_id of the C_Invoice is of a c_doctype that has the em_interco_is_intercompany set to Y
- The invoice hasn't been generated. That is, EM_INTERCO_ORIGINAL_INVOICE_ID is null
- The invoice is being completed (v_docaction = "CO").
Once the invoice is created it has to be completed calling back the C_INVOICE_POST procedure.
The only actions allowed for intercompany invoices are, complete when is in draft status and close when it is in completed status. Any other action has to raise an exception.
RAISE_APPLICATION_ERROR(-20000, '@ActionNotSupported@');
If the process fails it has to rollback the whole process, including the original invoice. This can be done raising an exception, doing a RAISE_APPLICATION_ERROR with an user friendly message.