How to color cell in APEX 5 Interactive Report - oracle-apex-5

I work in APEX 5 on some selling application and have Interactive Report displaying monthly review. It displays selling of some articles by days.
The source of this report is select from one table but columns of daily sale I get from function called from select clause.
select s.art_id, s.art_name
, f_daily_sale('01', :GLOBAL_MONTH, :GLOBAL_YEAR, s.art_id, 1) d_01
, f_daily_sale('02', :GLOBAL_MONTH, :GLOBAL_YEAR, s.art_id, 1) d_02
, f_daily_sale('03', :GLOBAL_MONTH, :GLOBAL_YEAR, s.art_id, 1) d_03
. . .
, f_daily_sale('31', :GLOBAL_MONTH, :GLOBAL_YEAR, s.art_id, 1) d_31
from sale s
where s.month = :GLOBAL_MONTH and s.year = :GLOBAL_YEAR
group by s.art_id, s.art_name;
What I need is to color columns that belong to Sunday, i.e. to red. And I want every daily cell to be clickable, to be a link to a modal page where I would display details.
How can I do this?
Thank you in advance.

On columns you can change type to link to open modal page with detail.
I hope this help:
with dts as (
select date'2017-01-01'+rownum-1 dt from dual
connect by level <= 366
)
select DT, 'data-style="background-color:red"' from dts
where to_char(dt, 'fmday', 'NLS_DATE_LANGUAGE=AMERICAN') = 'sunday';
This query return all sundays (date format) in 2017 with related css style for red cell.

Related

How to get SSRS to display correct Hours Worked Avg when using all parameter options?

Hi Currently we have a report that shows the hours worked by employee per pay period.
It includes the following parameters the user can select:
Period End From: Date
Period End To: Date
Company: (List of all companies inside Org) Use Select All
Department: (List of all Departments) Use Select All
Example of Sample Output: I run the report from 9/7 to 10/5 and it takes the the Avg for that period.
Exactly what it is supposed to do and how I have it programmed.
But... Once I go back and rerun the report and change the Period End From Date to 8/24 it switches the Avg to be 51.10 in which it should be 63.88... Has anyone ran into this issue?
Here is my expression that I have for the light blue box for the hours worked:
=Sum(Fields!PP_HOURS.Value) / (Fields!PAY_PER_COUNT.Value)
Here is a sample of my SQL code
select p.EMPLOYEE
, p.PER_BEG_DATE
, p.PER_END_DATE
, (e.FTE_TOTAL * 80) as FTE
, sum(p.HOURS) as PP_HOURS
, (select sum(t2.the_count) from (select 1 as the_count from [dbo].[PR_PRTIME] p where p.PER_END_DATE >= (#PER_END_DATE_FROM) and p.PER_END_DATE <= (#PER_END_DATE_TO) and p.PROCESS_LEVEL IN (#PROCLEVEL) group by p.PER_END_DATE) as t2) as PAY_PER_COUNT
from [dbo].[PR_PRTIME] p

How to add a value to future values?

So I am quite new to SQL so please be gentle.
I am using Oracle Apex to generate a bar chart showing the amount of storage used in a particular database over the last 12 months. In this chart I am trying to add an additional feature where the chart will show (via a line) how much storage will likely be used on a fortnightly basis over the course of the next three months.
I have created a PL/SQL function (GET_PREDICTED_VALUE) which generates the anticipated value I require, but I am having trouble using that value to show the predicted trend. If the generated anticipated value is positive, that’s how much more storage is needed. If the anticipated value is negative, that’s how much less storage is needed (the arguments sent into this function are how many days ago do I want to draw the ‘storage used’ values. 30 will be 30 days ago, 150 is 150 days ago etc).
What I would like to do is use this anticipated value and add it to the last ‘current storage used’ value recorded in the database. I would like the anticipated value to be continually added so that a future trend can be observed.
For example, if the last ‘current storage used’ value saved in the database is 50, and the anticipated value is 3, then the value for the immediate future date should be 53. And the next future value should be 56, and the next should be 59, and so on up to three months ahead.
This is the code I have so far, and it works insofar that the chart I need does get generated and the trend line runs across the previous year and then the future three months. But for the future three months, I am only able to get the trend line to represent the anticipated value, not the value continually added E.g again, if the anticipated value is 3, my trend line shows 3 across all future dates.
WITH src AS
(
SELECT GET_PREDICTED_VALUE(1, 30, 60, 90, 120, 150, 180) AS predictedValue FROM DUAL
),
mydays as
(
select level mylevel,
sysdate + level as futureDate
from dual
connect by level <= 90
),
future_values as
(
SELECT MAX(src.predictedValue) AS "ASM Used",
TO_CHAR(TRUNC(futureDate,'IW') ,'DD/MM/YY') AS "Capture Date",
TRUNC(futureDate,'IW') AS capture_date_order
FROM mydays
CROSS JOIN src
GROUP BY TRUNC(futureDate,'IW')
ORDER BY TRUNC(futureDate,'IW')
),
SRC_back AS
(
SELECT TRUNC(capture_date,'IW') AS week,
database_name,
MAX((os_usable_total_mb-os_usable_free_mb)) AS ASMUsed
FROM tablespace_used
WHERE capture_date >= (SYSDATE - 360)
GROUP BY TRUNC(capture_date,'IW'), database_name, tablespace_name
),
back_values as
(
SELECT /*+ parallel(a, 8) */
TO_CHAR(week,'DD/MM/YY') AS "Capture Date",
week AS capture_date_order,
ROUND( MAX(ASMUsed/1024/1024 ) ) AS "ASM Used"
FROM src_back a
WHERE week >= (SYSDATE - 360)
GROUP BY TO_CHAR(week,'DD/MM/YY'), week
ORDER BY 2
)
select "Capture Date", capture_date_order, "ASM Used" from back_values
union
select "Capture Date", capture_date_order, "ASM Used" from future_values
order by 2
I hope my explanation is clear, and if anyone could let me know what I have to do to get my trend line running the way I need?
(This is an image of how my chart looks so far):

Toad For Oracle: Bind Variable "End_Year" not Declared

I have pieced together the following code using recommendations from a couple different post and have hit a wall. My ultimate goal for this code is to find records from Oct 1st of last year to Sep 30th of the current year without prompting the user for input or having to hard code the date range in the between statement. I am currently receiving the following error "Bind variable "End_Year" not declared" when running the code.
declare
begin_Year date;
begin
select trunc(sysdate, 'YEAR')-92 FY_begin_year
Into begin_Year
from Dual;
end;
declare
End_Year date;
begin
select add_months(trunc(sysdate, 'YEAR'), 12)-93 FY_end_year
into End_Year
from dual;
end;
SELECT inv.company as company
, inv.customer_id as cust
, inv.address_id
,inv.invdate
, SUM(inv.sales) as sales
, SUM(inv.cost) as costs
FROM ifsinfo.hb_invoicing_all inv
WHERE inv.site IN ('06','01')
AND TO_DATE(inv.invdate) between :begin_Year and :End_Year
GROUP BY inv.company
, inv.customer_id
, inv.address_id
, inv.invdate
There are couple of things which are wrong with your query, first is to give alias to into clause. Also you have to encapsulate all the statments inside 1 PLSQL block.
Also what are you going to do with the select query. Are you displaying the output somewhere else?
The easiest way would be to use below query directly, instead of using 2 different variables.
SELECT inv.company as company
, inv.customer_id as cust
, inv.address_id
,inv.invdate
, SUM(inv.sales) as sales
, SUM(inv.cost) as costs
FROM ifsinfo.hb_invoicing_all inv
WHERE inv.site IN ('06','01')
AND TO_DATE(inv.invdate)
between
trunc(sysdate, 'YEAR')-92
and
add_months(trunc(sysdate, 'YEAR'), 12)-93
GROUP BY inv.company
, inv.customer_id
, inv.address_id
, inv.invdate
If you absolutely have to use variables, then put them in a same plsql block.
As mentioned by the others - you do not need any plsql block - just an sql query.
Now regarding your main goal
My ultimate goal for this code is to find records from Oct 1st of last
year to Sep 30th of the current year without prompting the user for
input or having to hard code the date range in the between statement
Given that Oct 1st of last year could be found as
to_date('01/10/'|| (to_number(to_char(sysdate,'YYYY'))-1),'dd/mm/rrrr')
and
Sep 30th of the current year is
to_date('30/09/'|| to_char(sysdate,'YYYY'),'dd/mm/rrrr')
your query becomes
SELECT inv.company as company
, inv.customer_id as cust
, inv.address_id
,inv.invdate
, SUM(inv.sales) as sales
, SUM(inv.cost) as costs
FROM ifsinfo.hb_invoicing_all inv
WHERE inv.site IN ('06','01')
AND TO_DATE(inv.invdate)
between
to_date('01/10/'|| (to_number(to_char(sysdate,'YYYY'))-1),'dd/mm/rrrr')
and
to_date('30/09/'|| to_char(sysdate,'YYYY'),'dd/mm/rrrr')
GROUP BY inv.company
, inv.customer_id
, inv.address_id
, inv.invdate
This is just another approach that may be a little bit more 'programmer friendly'.
If you decide to review your dates one day - you wouldn't have to calculate what the 93 and 92 stand for in trunc(sysdate, 'YEAR')-92 (your approach).

Oracle SQL. Display data for fixed number of periods from a dynamic start period

Here is the query I have: I would like to display 6 periods back and 12 periods forward from the value in the PERIOD column:
SELECT
item_id,
min(period),
min(picks_class),
min(vau_class),
min(warehouse_code),
min(stocked)
FROM
(select
i.warehouse_code,
ih.item_id,
ih.picks_class,
ih.period,
ih.vau_class,
ih.stocked,
substr(i.pareto_set, 6, 6) AS "Policy"
from d_item_history ih
join d_item_snapshot i on ih.item_id=i.id
where ih.picks_class='P2'
and i.supplier_code='DC'
and ih.valid_for_calc='Y'
and ih.vau_class in ('C1', 'C2')
and i.warehouse_code='YAFD'
-- and ih.item_id='1427084842208'
order by ih.period asc
)
group by item_id
;
Here is the output of the code: I would like to display the picks class for each one of the ITEM_IDs; 6 periods back from queried period and 12 months forward.
Please let me know if that is at all possible if/or how. All help is appreciated
When you want to calculate 6 periods back or 12 periods forward, Are you looking to move by months ? If so, the following code snippet might help you :
select to_char(add_months(to_date(period,'YYYYMM'),-6),'YYYYMM') PERIOD_6,
to_char(add_months(to_date(period,'YYYYMM'),12),'YYYYMM')PERIOD_12
from dual

Dynamic Grouping in SSRS 2012

I am developing a report that have parameter like
RowGroupLevel1,
RowGroupLevel2,
ColumnGroupLevel1,
ColumnGroupLevel2,
ColumnGroupLevel3
Row Group Contain Category, Executive Name, Client Name Like Field
Column Group Contain Year,Quarter,Month Field.
So My requirement is as like except Level1 in Row and Column Grouping other fields are optional.
For An Example : if I am selecting as below
scenario 1 :
RowGroupLevel1 - Category
RowGroupLevel2 - Executive Name
ColumnGroupLevel1 - Year
ColumnGroupLevel2 - Quaker
ColumnGroupLevel3 - Month
scenario 2 :
RowGroupLevel1 - Category
RowGroupLevel2 -
ColumnGroupLevel1 - Year
ColumnGroupLevel2 - Month
ColumnGroupLevel3 -
so as per above scenario how I can grouping my report dynamically.
Please help me to create any type of SSRS report.
Thanks in advance.
Ankit Gusani
The easiest way to achieve this is to first of all write your query which pulls forward the results like this.
SQL Server Query
SELECT DATEPART(WEEK, Date_Column) AS [Weekly]
,DATEPART(MONTH, Date_Column) AS [Monthly]
,DATEPART(YEAR, Date_Column) AS [Yearly]
,SUM(Some_Column) AS Total
FROM Table_Name
GROUP BY DATEPART(MONTH, Date_Column)
,DATEPART(WEEK, Date_Column)
,DATEPART(YEAR, Date_Column)
SSRS Report
Add a Matrix Data region. Drag and drop Total column to DATA.
Create a Parameter say GROUP ON of Text type, and provide values
1) Weekly
2) Monthly
3) Yearly
Now below in ROW GROUPS pane, right click the only visible Row Group and goto GROUP PROPERTIES
In GROUP ON section put following expression.
=SWITCH(
Parameters!Groupby.Value = "Weekly", Fields!Weekly.Value
,Parameters!Groupby.Value = "Monthly", Fields!Monthly.Value
,Parameters!Groupby.Value = "Yearly", Fields!Yearly.Value
)
Use the exactly same Expression on Data region ROWS section.
For Column name you can use the following Expression...
=SWITCH(
Parameters!Groupby.Value = "Weekly", "Weekly"
,Parameters!Groupby.Value = "Monthly", "Monthly"
,Parameters!Groupby.Value = "Yearly", "Yearly"
)
and you are good to go.
Important Note
SSRS is a cool tool for data presentation, not so cool when it comes to Data manipulation, to get better performance do all sorts of Data Manipulation closer to source (database, SQL Server).
All of the presentation stuff should be handled on SSRS.