Product Correlation within an invoice?

Hi All,

Just wondering if anyone has any suggestions as to how I can look to see if two specific products or product types have been (or have not been) charged on the same invoice and to then see the details for these.

Eg: 

  • Product Type Surgery + Product type anaesthetic

​OR

  • Specific product (eg: vaccination or SR12 inj) without a consultation?

I think I can do it in a big data crunch in excel, but looking for a simpler solution or suggestions.

 

Many thanks

David

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Product Correlation within an invoice?

It can be done in SQL, and therefore in a JasperReport.

The following SQL finds all invoices that have both surgery and anaesthetic product types:

select invoice.act_id invoice_id, product1.entity_id product_id1, product1.name product_name1, product_type1.name product_type1,
    product2.entity_id product_id2, product2.name product_name2, product_type2.name product_type2
from acts invoice
join act_relationships items1
    on items1.source_id = invoice.act_id
        and items1.arch_short_name = 'actRelationship.customerAccountInvoiceItem'
join acts item1
    on item1.act_id = items1.target_id
join participations pproduct1
    on item1.act_id = pproduct1.act_id
        and pproduct1.arch_short_name = 'participation.product'
join entities product1
    on pproduct1.entity_id = product1.entity_id
join entity_links product_type_link1
    on product1.entity_id = product_type_link1.source_id
        and product_type_link1.arch_short_name = 'entityLink.productType'
join entities product_type1
    on product_type_link1.target_id = product_type1.entity_id
join act_relationships items2
    on items2.source_id = invoice.act_id
        and items2.arch_short_name = 'actRelationship.customerAccountInvoiceItem'
join acts item2
    on item2.act_id = items2.target_id
join participations pproduct2
    on item2.act_id = pproduct2.act_id
        and pproduct1.arch_short_name = 'participation.product'
join entities product2
    on pproduct2.entity_id = product2.entity_id
join entity_links product_type_link2
    on product2.entity_id = product_type_link2.source_id
        and product_type_link2.arch_short_name = 'entityLink.productType'
join entities product_type2
    on product_type_link2.target_id = product_type2.entity_id
where item1.act_id <> item2.act_id
    and product_type1.name = 'Surgery' and product_type2.name = 'Anaesthetic'
group by invoice_id;

 

The following finds all invoices that have a 'Vaccination' product, but no 'Consultation' product:

select invoice.act_id
from acts invoice
join act_relationships items1
    on items1.source_id = invoice.act_id
        and items1.arch_short_name = 'actRelationship.customerAccountInvoiceItem'
join acts item1
    on item1.act_id = items1.target_id
join participations pproduct1
    on item1.act_id = pproduct1.act_id
        and pproduct1.arch_short_name = 'participation.product'
join entities product1
    on pproduct1.entity_id = product1.entity_id
where product1.name = 'Vaccination' and not exists (
    select *
    from act_relationships items2    
    join acts item2
            on items2.arch_short_name = 'actRelationship.customerAccountInvoiceItem'
            and item2.act_id = items2.target_id
    join participations pproduct2
        on item2.act_id = pproduct2.act_id
            and pproduct2.arch_short_name = 'participation.product'
    join entities product2
        on pproduct2.entity_id = product2.entity_id
    where items2.source_id = invoice.act_id and product2.name = 'Consult')
group by invoice_id;

 

Re: Product Correlation within an invoice?

Hi Tim,

Thanks for this.  Much appreciated

 

Cheers

David

Syndicate content