Generate a transaction report with all the database tables in Unicentapos - mysql

I am trying to generate report in unicentaopos4.2.2. The report is created in Jasper but there is a corresponding bs file. There is only one SQL query and for my report I need multiple query in the jrxml file.
This is the sales_extendedcashregisterlog.bs file that have only one SQL query with the report.setSentence().
report = new com.openbravo.pos.reports.PanelReportBean();
report.setTitleKey("Menu.ExtendedCashRegisterLog");
report.setReport("/com/openbravo/reports/sales_extendedcashregisterlog");
report.setResourceBundle("com/openbravo/reports /sales_extendedcashregisterlog_messages");
report.setSentence("SELECT " +
"tickets.TICKETID AS TICKET_NO, " +
"receipts.DATENEW AS TICKET_DATE, " +
"people.NAME AS PERSON, " +
"payments.PAYMENT AS PAYMENT, " +
"payments.NOTES, " +
"payments.TOTAL AS MONEY, " +
"payments.TENDERED " +
"FROM ((tickets tickets " +
"LEFT OUTER JOIN people people ON (tickets.PERSON = people.ID)) " +
"RIGHT OUTER JOIN receipts receipts ON (receipts.ID = tickets.ID)) " +
"LEFT OUTER JOIN payments payments ON (receipts.ID = payments.RECEIPT) " +
"WHERE ?(QBF_FILTER) " +
"ORDER BY TICKET_DATE ASC");
report.addParameter("receipts.DATENEW");
report.addParameter("receipts.DATENEW");
paramdates = new com.openbravo.pos.reports.JParamsDatesInterval();
paramdates.setStartDate(com.openbravo.beans.DateUtils.getToday());
// JG - 8 Jan 14 paramdates.setEndDate(com.openbravo.beans.DateUtils.getToday());
paramdates.setEndDate(com.openbravo.beans.DateUtils.getTodayMinutes());
report.addQBFFilter(paramdates);
report.addField("TICKET_NO", com.openbravo.data.loader.Datas.STRING);
report.addField("TICKET_DATE", com.openbravo.data.loader.Datas.TIMESTAMP);
report.addField("PERSON", com.openbravo.data.loader.Datas.STRING);
report.addField("PAYMENT", com.openbravo.data.loader.Datas.STRING);
report.addField("NOTES", com.openbravo.data.loader.Datas.STRING);
report.addField("MONEY", com.openbravo.data.loader.Datas.DOUBLE);
report.addField("TENDERED", com.openbravo.data.loader.Datas.DOUBLE);
return report;
Now we have a jrxml file. I can edit this file using pallet feature but the thing is the sql query that give me the fields so that I can use them. here is the query of the jrxml file that it already have.
queryString>
<![CDATA[SELECT
tickets.TICKETID AS TICKET_NO,
receipts.DATENEW AS TICKET_DATE,
payments.TOTAL AS MONEY,
people.NAME AS PERSON,
payments.PAYMENT AS PAYMENT
FROM receipts
LEFT JOIN tickets ON receipts.ID = tickets.ID
LEFT JOIN payments ON receipts.ID = payments.RECEIPT
LEFT JOIN people ON tickets.PERSON = PERSON.ID
ORDER BY tickets.TICKETID]]>
</queryString>
<field name="TICKET_NO" class="java.lang.String"/>
<field name="TICKET_DATE" class="java.util.Date"/>
<field name="PERSON" class="java.lang.String"/>
<field name="PAYMENT" class="java.lang.String"/>
<field name="NOTES" class="java.lang.String"/>
<field name="MONEY" class="java.lang.Double"/>
<field name="TENDERED" class="java.lang.Double"/>
the fields are already inside. Now I want to add more than one sql query, so how exactly I can do it.
Basically I am trying to generate a transaction log in unicentaopos with all the needed data.

Related

Quantity in stock in stock locations in Exact Online

Using the following query, I found that for items that have a stock location, there are multiple rows returned from the REST API StockLocations of Exact Online:
select spn.item_code_attr || '-' || spn.warehouse_code_attr || '-' || stn.code key
, itm.itemgroupcode
, itm.itemgroupdescription
, spn.item_code_attr
, spn.item_description
, spn.currentquantity
, spn.planning_in
, spn.planning_out
, spn.currentquantity + spn.planning_in - spn.planning_out plannedquantity
, -1 bestelniveau /* out of scope */
, itm.costpricestandard costprijs
, itm.costpricestandard * spn.currentquantity stockvalue
, spn.warehouse_code_attr
, stn.code locatie
, itm.unitcode UOM
, itm.id
, whe.id
, sln.stock
, sln.itemid
, sln.warehouse
, stn.id
from exactonlinexml..StockPositions spn
join exactonlinerest..items itm
on itm.code = spn.item_code_attr
and itm.code = 'LE-10242'
and itm.isstockitem = 1
join exactonlinerest..warehouses whe
on whe.code = spn.warehouse_code_attr
left
outer
join exactonlinerest..stocklocations sln
on sln.itemid = itm.id
and sln.stock != 0
and sln.warehouse = whe.id
left
outer
join storagelocations stn
on stn.id = sln.storagelocation
and stn.warehouse = sln.warehouse
--
-- Filter out no stock nor planned.
--
where ( spn.currentquantity !=0
or
spn.planning_in != 0
or
spn.planning_out != 0
)
and spn.item_code_attr = 'LE-10242'
order
by key
For example, for this item, there are 10 StockLocations. When I sum the field Stock, it returns the stock quantity found in StockPositions. However, it seems that every transaction creates an additional StockLocation entry.
I would expect StockLocation to contain per location in stock the total amount to be found there.
EDIT
The StockLocations API is described in https://start.exactonline.nl/api/v1/{division}/logistics/$metadata as:
<EntityType Name="StockLocation">
<Key>
<PropertyRef Name="ItemID"/>
</Key>
<Property Name="ItemID" Type="Edm.Guid" Nullable="false"/>
<Property Name="Warehouse" Type="Edm.Guid" Nullable="true"/>
<Property Name="WarehouseCode" Type="Edm.String" Nullable="true"/>
<Property Name="WarehouseDescription" Type="Edm.String" Nullable="true"/>
<Property Name="Stock" Type="Edm.Double" Nullable="true"/>
<Property Name="StorageLocation" Type="Edm.Guid" Nullable="true"/>
<Property Name="StorageLocationCode" Type="Edm.String" Nullable="true"/>
<Property Name="StorageLocationDescription" Type="Edm.String" Nullable="true"/>
</EntityType>
Somehow it is not documented at https://start.exactonline.nl/docs/HlpRestAPIResources.aspx
What am I doing wrong?
Discussed question on Hackathon with engineer. This is as the StockLocation API works; the naming does not optimally reflect the contents, but this is intended behaviour.
With a select field, sum(stock) from stocklocations group by field, you can get the right information.
To improve join performance, it is recommended to use an inline view for this such as select ... from table1 join table2 ... join ( select field, sum(stock) from stocklocations group by field).

NonUniqueDiscoveredSqlAliasException for MySQL query that works in phpMyAdmin

I have a table with four foreign keys and an image:
+--------------+--------------+---------------------+---------------------+-------+
| dataset_1_fk | dataset_2_fk | attribute_type_1_fk | attribute_type_2_fk | image |
+--------------+--------------+---------------------+---------------------+-------+
Using the name of two datasets, I would like to select the image and names of the two attributes. Here is my Hibernate code:
HibernateUtil
.getCurrentSession()
.createSQLQuery(
"SELECT ddm.image, at1.name, at2.name " +
"FROM dataset_dataset_matrices AS ddm " +
" JOIN dataset AS d1 ON d1.id = ddm.dataset_1_fk " +
" JOIN dataset AS d2 ON d2.id = ddm.dataset_2_fk " +
" JOIN attribute_type AS at1 ON at1.id = ddm.attribute_type_1_fk " +
" JOIN attribute_type AS at2 ON at2.id = ddm.attribute_type_2_fk " +
"WHERE d1.name = :dataset_1 AND d2.name = :dataset_2"
)
.setString("dataset_1", dataset_1)
.setString("dataset_2", dataset_2)
.list();
I receive this error when it executes:
org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias [name] during auto-discovery of a native-sql query
at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:594)
But when I issue the same query from phpMyAdmin, it works fine. Also, if I remove either at1.name or at2.name from the SELECT statement, the query works in Hibernate. How can I fix this?
Try giving different alias name to your select columns like
"SELECT ddm.image as col1, at1.name as col2, at2.name as col3"
It seems hibernate doesn't generate the different alias automatically. If the query results has same values this issue may happens.
Reference : https://github.com/querydsl/querydsl/issues/80

with-clause not allowed on fetched associations

I have a name query like the one below - but keep getting an error from Hibernate that it will not allow my 'with'-clause since I'm doing join fetch.
I need to do join fetch - because it there is a related item then I wan't it to be present on the object.
#NamedQuery(name = "Item.findItem",
query = "SELECT DISTINCT(c) FROM Item c " +
"JOIN FETCH c.storeRelations as childStoreRelation " +
"LEFT JOIN FETCH c.relatedItems as relatedRelations WITH relatedRelations.store.id = childStoreRelation.store.id " +
"WHERE c.id = :itemId " +
"AND childStoreRelation.store.id = :storeId " +
"AND childStoreRelation.deleted <> 'Y' " +
"ORDER BY c.partnumber "),
Suggestion would be to move the 'with' part to my where clause - but this will cause invalid results.
Consider item A which might have to items related to it - but for some stores the relations are not valid.
If put in where clause then the store without relations will not shown the main item, since SQL will be build by Hibernate so it requires that if any relations exist, then they must be valid for the store - otherwise nothing is fetched :-(
So the classic fix found many places (store.id is null OR store.id = :storeId) will not work.
Does someone have another work around?
I'm running Hibernate 4.3.11
Thanks in advance
You cannot use LEFT JOIN FETCH with clause.
Please remove WITH clause and move them to WHERE clause.
It should like this:
#NamedQuery(name = "Item.findItem",
query = "SELECT DISTINCT(c) FROM Item c " +
"JOIN FETCH c.storeRelations as childStoreRelation " +
"LEFT JOIN FETCH c.relatedItems as relatedRelations " +
"WHERE c.id = :itemId " +
"AND relatedRelations.store.id = childStoreRelation.store.id" +
"AND childStoreRelation.store.id = :storeId " +
"AND childStoreRelation.deleted <> 'Y' " +
"ORDER BY c.partnumber "),
You need the ON keyword rather than the WITH keyword.

Solr Java Index Searching

I'm new to Solr , actually I'm trying search data from mysql using Solr Index Search method, when I search single data, it's shows multiple data related to the Index,
for eg:
Company table:-
Id company_name company_id company_emp
1 Xx 1 Xx
2 yy 2 Yy
empDetail:-
Id company_id company_empA emp_city emp_mobile
1 1 dd ss 32455
2 1 cc cc 344444
3 1 zz zz 56778998
Here I have used OneToMany relationship between Company table and Employee Detail Table, When I search ss from emp_City , it's gives all data which is related to Company_id instead of only ss
Current result show like this
id company_id company_name company_empA emp_city
1 1 Xx dd ss
2 1 Xx cc cc
3 1 Xx zz zz
the above result shows all the emp_city value which is related to the Company_id. but I want to get only ss.
I have configured Data-config.xml Solr configuration file as follow
<document name="company1">
<entity name="companys" pk="id" query="SELECT * FROM company" deltaImportQuery="select * from company where id='${dataimporter.delta.id}'" >
<field column="company_id" name="id" />
<field column=" company_name " name=" company_name " />
<field column=" company_emp " name=" company_emp " />
<field column="company_id" name="companyId"/>
<entity name="companyDetails" pk="id " query="select * from company_detail where company_id='${companys.company_id}' ORDER BY '${companys.company_id}'"
parentDeltaQuery="select id from company_detail where company_id=${companys.company_id}">
<field column="company_id" name="id"/>
<field column="company_id" name="com_companyId"/>
<field column="company_empA" name="com_companyemp"/>
<field column=" emp_city " name=" emp_city" />
<field column=" emp_mobile " name=" emp_mobile "/>
</entity>
</entity>
I think the problem is in this Query, but I couldn't find it out, kindly help me to resolve it. thanks in advance.

Complex JPQL ORDER statement

I'm trying to write a fairly complex JPQL statement that sorts results based on a value in another table. I know what the MySQL would look like, but I need help turning it into JPQL. Here's the equivalent SQL:
SELECT o.* FROM Observation o
LEFT JOIN Obs_Event p
ON p.Event_ID = o.Event_ID
LEFT JOIN Event_Set ppp
ON ppp.Event_ID = o.Event_ID AND ppp.Event_Set_ID = o.Event_Set_ID
WHERE o.Individual_ID = <some id>
AND o.Observation_Date = <a date value>
ORDER BY ppp.Seq_Num ASC
Any help on how to do this would be much appreciated. Specifically I seem to having trouble with this part:
ON ppp.Event_ID = o.Event_ID AND ppp.Event_Set_ID = o.Event_Set_ID
So, far I've tried this:
Query q= em.createQuery("select o " +
" from Observation as o " +
" join o.eventID p" +
" join p.eventSetCollection ppp " +
" where o.individualID = :indiv " +
" AND o.observationDate = :d " +
" AND o.eventID = ppp.event " +
"";
If I try to add something like
WHERE ...
AND o.eventSetID = ppp.eventSet
... it simply doesn't work. If I look at the generated SQL, it looks like ppp.eventSet is simply ignored.
Suggestions?
So, first thanks to the poster that commented, asking for my entity relationships. That forced me to take a closer look at things and realize what was wrong.
As it turns out, back when I was even worse at JPA than I am now, I set the o.eventID property to an actual Integer, as in the primary key of the record/object, instead of an actual object. Hence, in the JPQL above, I'm actually trying to map an object to an integer in the following statement:
AND o.eventID = ppp.event
turns out the correct statement is:
Query q= em.createQuery("select o " +
" from Observation as o " +
" join o.eventID p" +
" join p.eventSetCollection ppp " +
" where o.individualID = :indiv " +
" AND o.observationDate = :d " +
" AND o.eventID= ppp.event.eventID" +
" order by ppp.seqNum ASC" +
"");
This works in a pinch, although I should eventually change that relationship in the Observation class to actually go to an object.