BI Report query to get shipping method and carrier name for sales order lines in oracle fusion - bi-publisher

I'm trying to create a BI Report which queries sales order lines details, including shipping method and carrier name. But I'm unable to find the correct joins for this. Till now I have an alternative query which retrieves carrier_name for the sales order lines for me, but only retrieves sales order lines which have status as "Closed" or "Awaiting Billing". The Oracle Fusion version is release 22A (11.13.22.01.0)
select dfla.source_order_number, wdd.sales_order_line_number ,wcv.carrier_name
FROM wsh_new_deliveries wnd,
wsh_carriers_v wcv,
wsh_delivery_assignments wda,
wsh_delivery_details wdd,
doo_fulfill_lines_all dfla
where wcv.carrier_id = wnd.carrier_id
AND wda.DELIVERY_ID = wnd.DELIVERY_ID
AND wdd.delivery_detail_id = wda.delivery_detail_id
AND dfla.fulfill_line_id=wdd.source_shipment_id

Related

JIRA Query to track any and all activity between certain hours

A contractor I'm working with wants to give us a small bonus based on any "overtime" work we may or may not have done. Problem is, we didn't exactly keep a log of any activity we did outside of normal working day hours. I'm trying to use my Jira activity as a starting point. How can I track any and all activity (leaving a comment, changing a status, assigning the ticket to someone else, etc) conducted by me within certain hours, within certain dates.
For example, any and all activity conducted by me between the hours of 7PM - 8AM from February 3, 2021 to January 15, 2022.
You can get it from the Jira database.
For any activity, you can use following SQL query for retrieve any change in a project:
SELECT p.pname, p.pkey, i.issuenum, cg.ID, cg.issueid, au.lower_user_name, cg.AUTHOR, cg.CREATED, ci.FIELDTYPE, ci.FIELD, ci.OLDVALUE, ci.OLDSTRING, ci.NEWVALUE, ci.NEWSTRING
FROM changegroup cg
inner join jiraissue i on cg.issueid = i.id
inner join project p on i.project = p.id
inner join changeitem ci on ci.groupid = cg.id
inner join app_user au on cg.author = au.user_key
WHERE p.pkey = '<PROJECT_KEY>'
order by 1,3,4;
You can modify that query by filtering cg.CREATED in order to get activity between certain dates.
NOTE: Query can be changed depend on your database.
NOTE2: You can look that Atlassian link for further information.

Need help writing sql query in rails so I get ActiveRelation

I need an active record relation that gives me the latest record of a region, city, bed combination. I have the sql query written as below, but I need to figure out if there is away to use a different approach to have it return an active record relation and not an array. Any suggestions?
Current query:
#current_ltm_market_stats = LtmStatsByBedCount.find_by_sql(" SELECT *
FROM ltm_stats_by_bed_counts lstats
WHERE lstats.city_id = '#{#city_id}'
#{#region_id_condition}
AND (lstats.beds,lstats.city_id,lstats.region_id,lstats.reporting_date)
IN (SELECT lstats.beds,
lstats.city_id,
lstats.region_id,
max(lstats.reporting_date)
FROM ltm_stats_by_bed_counts lstats
WHERE lstats.city_id = '#{#city_id}'
#{#region_id_condition}
GROUP BY city_id, region_id, beds)
ORDER BY lstats.year DESC,lstats.month DESC")
I had tried this before which did result in a relation but it runs really slowly and the result is not exactly the same. Are there any better rails ways to do this?
#all_ltm_market_stats = LtmStatsByBedCount.where(city_id: #market.city_id, region_id: #market.region_id)
#current_ltm_market_stats = #latest_year_ltm_market_stats.where(month: #latest_year_ltm_market_stats.all_ltm_market_stats.select('Max(year)'))
Information in the question is incomplete, so i might have to update my answer when additional details are added, But here is the initial draft with available information:
#current_ltm_market_stats = LtmStatsByBedCount.
where(city_id: #city_id).
where(#region_id_condition).
where("(beds, city_id, region_id, reporting_date) IN (
SELECT lstats.beds,
lstats.city_id,
lstats.region_id,
max(lstats.reporting_date)
FROM ltm_stats_by_bed_counts lstats
WHERE lstats.city_id = '#{#city_id}'
#{#region_id_condition}
GROUP BY city_id, region_id, beds)").
order(year: :desc, month: :desc)
Note that you might have to adjust your #region_id_condition a bit for this to work.
Theoretically it is equivalent of your SQL version(which means it will generate same sql excluding table alias) and returns the AR relation object. Which is the only requirement in the question. Obviously SQL might be improved with additional information as well.
Additionally, you will want to have carefully crafted indexes on this table if you are going to use this query on larger datasets frequently.

Jira aggregate worklogs only in specific dates range

JIRA has an excellent ability to search issues with workLog items created in specific date and by a specific user. For example:
worklogDate > 2017-04-01 AND worklogDate < 2017-05-01 AND worklogAuthor = some-user
In this search result I can see a column Time Spent - it's a total time spent on a task. How can I aggregate time from workLogs only for selected days? For example, we worked on the task in Mar and April. How to write JQL to calculate only April's time.
It is possible?
To get the time spent by the user by tasks, if you have access to the database, you can run this query:
select wl.timeworked, wl.worklogbody, wl.updateauthor, wl.updated,
u.display_name, ji.summary,
concat(concat(p.pkey,'-'),ji.issuenum) as IssueKey
from worklog wl
inner join cwd_user u
on wl.updateauthor = u.user_name
inner join jiraissue ji
on ji.id = wl.issueid
inner join project p
on (ji.project = p.id)
where issueid in (
select j.ID
from jiraissue j
inner join project p
on (j.project = p.id)
where u.user_name = 'userid')
Replace the userid with the userid of the person that submitted the worklog. Take note that for each JIRA ticket (issue), there can be multiple worklog submission by different user. This will give you every worklog submitted by the userid and it will also show you which ticket (issue) they are for. You can add in the date constraint in the where clause if you want to just query for specific timeframe. The unit of measurement for the timeworked column is in second as recorded by JIRA.
According to Time Since Issues Report if JIRA's Documentation, Time Spend is the amount of time spent on the issue. This is the aggregate amount of time that has been logged against this issue. Are you looking to aggregate the time of one person in different issues?

Get number of jira users

How can I get the number of JIRA users? And how can I get the user number JIRA is licenced for?
I'll appreciate if you provide examples using different layers e.g. Using database query, or JIRA API call, or a method to call in JIRA plugin.
// JIRA instance is using Crowd
This is how to get users from group jira-users. Only this user group affects license user count.
ComponentAccessor.getGroupManager().getUserNamesInGroup("jira-users").size();
You could also inject groupManager in your plugin.
I don't know how to get user number JIRA is licenced for. I think it's not stored in your instance data or DB.
have a look at https://confluence.atlassian.com/jirakb/get-list-of-licensed-users-in-jira-server-278695452.html
But to have the exact licence count, the SQL query must be improved by adding this clause << AND group_id = 'jira-users' >>
So the query is :
SELECT DISTINCT u.lower_user_name
FROM cwd_user u
JOIN cwd_membership m
ON u.id = m.child_id
AND u.directory_id = m.directory_id
JOIN licenserolesgroup lrg
ON Lower(m.parent_name) = Lower(lrg.group_id)
JOIN cwd_directory d
ON m.directory_id = d.id
WHERE d.active = '1'
AND u.active = '1'
AND license_role_name = 'jira-software'
AND group_id = 'jira-users'; // <- improvement

Report using Rails ActiveRecord group by

I am trying to generate a report to screen of accounting transaction history. In most situations it is one display row per record in the AccountingTransaction table. But occasionally there are transactions that I wish to display to the end user as one transaction which are really, behind the scenes, two accounting transactions. This is caused by deferral of revenues and fund splitting since this app is a fund accounting app.
If I display all rows one by one, those double entries look odd to the user since the fund splitting and deferral is "behind the scenes". So I want to roll up all the related transactions into one display row on screen.
I have my query now using group by to group the related transactions
#history = AccountingTransaction.where("customer_id in (?) AND no_download <> 1", customers_in_account).group(:transaction_type_id, :reference_id).order(:created_at)
as I loop through I get the transactions grouped as I want but I am struggling with how to display the total sum of the 'credit' field for all records in the group. (It is only showing the credit for the first record of the group) If I add a .sum(:credit) to my query, of course, it returns the sums just as I want but not all the other data.
Is there a way for me to group these records like in my #history query and also get the sum of the credit field for each respective group?
* Addition *
What I really want is what the following SQL query would give me.
SELECT transaction_type_id, reference_id, sum(credit)
WHERE customer_id in (21,22,23,24) AND no_download <> 1
GROUP BY reference_id, transaction_type_id ORDER BY created_at
I'm not sure you can do "ORDER BY created_at" and not include it in the select fields, but here is an example.
#history = AccountingTransaction.
select([:reference_id, :transaction_type_id, :created_at]).
select(AccountingTransaction.arel_table[:credit].sum.as("credit_sum")).
where("customer_id in (?) AND no_download <> 1", customers_in_account).
group(:transaction_type_id, :reference_id).
order(:created_at)
To access the credit_sum you could do:
#history[0].attributes["credit_sum"]
I guess if you'd like, you could create a method:
def credit_sum
attributes["credit_sum"]
end
EDIT *
As stated in comments you can access the attribute directly:
#history[0].credit_sum

Resources