How do you extract invoice lines from an openvpms database
Hi,
Our software project requires us to extract every invoice line for legitimate/completed invoices (so exclude any estimates or quotes) to petowners. We are doing this for multiple systems but are struggling to map this accurately in openvpms
The data required is:
client ID (unique identifier of pet owner)
user_id (unique identifier of user who entered the invoice line or invoice)
user_name (name of the user who entered the invoice line or invoice)
date_created (date the invoice line was entered)
is_deleted (this is just a tag so that we can identify deleted line items or invoices)
quantity (quantity of product sold)
line_total_inc_tax (tax inclusive amount for the total invoice line. Or we just need to know if the value is inc or exc tax)
product_id (unique identifier for the product/fee charged)
description (description/name of the product/service sold)
unit_price (unit price of the product/service - although we could work this out from the above, its nice to cross check)
Can anyone give us an SQL query that will return this result?
Thanks
Re: How do you extract invoice lines from an openvpms database
My advice would be simple mount a development database and you can build that sort of query quite easily - you need to look at
act.customerAccountInvoiceItem
act.customerAccountChargeItem
act.customerAccountCreditItem
primarily these are the line item archetypes we use to record invoice items, coutersale items and credited items
They are accessed in the act table and the act_detail table as well as actRelationship table and participation table.
For examples of SQL you can look here
http://www.openvpms.org/templates
these templates are in the form of JRXML which user the jasperstudion reporting interface to produce the data.
The reports will all have embedded sql statements to extract the data - it should give you a good headstart on creating the sql you need.
Re: How do you extract invoice lines from an openvpms database
Ben beat me to it - looking at the sql in the jrxml files is very useful. What you also want is a test database and the mysql workbench - though the sql editor in Jaspersoft's Studio product is almost as good - though its syntax checker is a bit wonky.
here is the parameter input screen for one of my reports:
Here is the sql that implements the above:
select product.name as product, customer.name as customer, customer.entity_id as customer_id, patient.name as patient, patient.entity_id as patient_id, child.activity_start_time as date, if(credit,-f.quantity, f.quantity) as quantity, if(credit,-f.total,f.total)as total from acts parent join act_relationships r on parent.act_id = r.source_id join acts child on r.target_id = child.act_id and child.arch_short_name like "act.customerAccount%Item" join participations product_partic on child.act_id = product_partic.act_id join entities product on product.entity_id = product_partic.entity_id and product.arch_short_name like "product.%" left join participations patient_partic on child.act_id = patient_partic.act_id and patient_partic.arch_short_name = "participation.patient" left join entities patient on patient.entity_id = patient_partic.entity_id and patient.arch_short_name like "party.patient%" join participations cust_partic on parent.act_id = cust_partic.act_id and cust_partic.arch_short_name = "participation.customer" join entities customer on customer.entity_id = cust_partic.entity_id and customer.arch_short_name like "party.%" join financial_acts f on f.financial_act_id = child.act_id left join participations pl ON parent.`act_id` = pl.`act_id` and pl.arch_short_name = "participation.location" left join `entities` l ON pl.`entity_id` = l.`entity_id` left join entity_classifications productgroup on productgroup.entity_id = product.entity_id left join lookups grouplookup on grouplookup.lookup_id = productgroup.lookup_id left join entity_relationships rpt on rpt.target_id = product.entity_id and rpt.arch_short_name = "entityRelationship.productTypeProduct" left join entities producttype on producttype.entity_id = rpt.source_id where parent.activity_start_time between $P{startDate} and date_add($P{endDate}, INTERVAL "23:59:59" HOUR_SECOND) and product.name like concat(ifnull($P{productName},""),"%") and customer.name like concat(ifnull($P{customerName},""),"%") and l.name like concat(ifnull($P{locationName},""),"%") and if($P{classification} is null,(grouplookup.name like concat(ifnull($P{classification},""),"%") or grouplookup.lookup_id is null),grouplookup.name like concat(ifnull($P{classification},""),"%")) and if($P{productType} is null,(producttype.name like concat(ifnull($P{productType},""),"%") or producttype.entity_id is null),producttype.name like concat(ifnull($P{productType},""),"%")) group by child.act_id order by customer.name, patient.name, child.activity_start_time
As Ben said, you do need to look at the archetypes - ie fire up your openvpms test system and use Administration|Archetypes. Also read http://www.openvpms.org/documentation/csh/1.8/admin/archetype#archetypeDef
Also, if you are trying to understand OpenVPMS, look at http://www.openvpms.org/documentation/csh/1.8/concepts
A couple of other comments:
Have fun, regards Tim G
Re: How do you extract invoice lines from an openvpms database
Thanks.
Got it all working now.