Total Pageviews

2014/07/11

[iReport] How to format text style in text field

Requirement
The first row in this report, the report name will be appended "總預算\n" before report name. And "總預算" should be bold font. 


Solution
Step 1. Set Text Field Expression

Step 2. Set properties Markup = styled for this text field.

Reference



[iReport] How to apply conditional formatting to your text fields

Requirement
In iReport, I wish to apply different formats to my text fields based on different conditions. For instance, when "融資項目別"== "特別預算" then the font should be bold font.

Solution
You can apply "Conditional Styles" to fulfill this requirement.
Step1. Add new Style

Step2. Add new Conditional Style

Step3. Edit Condition Expression

Step4. Set Bold attribute to be true

Step5. Select text fields and apply this style

Step6. Test


Reference
[1] http://community.jaspersoft.com/wiki/how-apply-conditional-formatting-your-text-fields

2014/07/08

ORA-30926: unable to get a stable set of rows in the source tables when Merging tables

Problem
When I executed the merge SQL statement in my web application
MERGE INTO FMS434FB T1 USING
  (SELECT ACCYR AS ACCYR,
          MONTH AS MONTH,
          ASP AS ASP,
          AMT7,
          AMT9,
          AMT7+AMT9 AS ACC_AMT9
   FROM FMS434FB
   WHERE ACCYR||MONTH = :LAST_YYY_MM) T2 ON(T1.ACCYR||T1.MONTH = :YYY_MM
   AND T1.ASP=T2.ASP) WHEN MATCHED THEN
UPDATE
SET T1.AMT7 = T2.ACC_AMT9

It throw this exception
1:  Caused by: java.sql.SQLException: ORA-30926: unable to get a stable set of rows in the source tables when Merging tables  
2:       at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447) ~[oracle.jdbc-11.2.0.4-java-6.jar:11.2.0.3.0]  
3:       at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) ~[oracle.jdbc-11.2.0.4-java-6.jar:11.2.0.3.0]  
4:       at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951) ~[oracle.jdbc-11.2.0.4-java-6.jar:11.2.0.3.0]  
5:       at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513) ~[oracle.jdbc-11.2.0.4-java-6.jar:11.2.0.3.0]  
6:       at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227) ~[oracle.jdbc-11.2.0.4-java-6.jar:11.2.0.3.0]  
7:       at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531) ~[oracle.jdbc-11.2.0.4-java-6.jar:11.2.0.3.0]  


Root Cause
ORA-30926 results from the using statement has duplicate data.
Therefore, as I execute this part of SQL statement
SELECT ACCYR AS ACCYR,
       MONTH AS MONTH,
                ASP AS ASP,
                AMT7,
                AMT9,
                AMT7+AMT9 AS ACC_AMT9
FROM FMS434FB
WHERE ACCYR||MONTH = :LAST_YYY_MM
It really has duplicated data !



2014/07/06

本益比的計算

漫步華爾街的作者提到:
選擇低本益比的股票比較好,如果成長實現,將帶來加倍利潤;若成長失敗,損失也有限

本益比計算公式如下

本益比=股價/EPS,所以股價=本益比 * EPS

先到網站上查詢最近五年的最高與最低本益比,算出最高本益比平均最低本益比平均以及平均本益比

再從網站上查詢最近四季的EPS總和

再推算出,當本益比是多少的時候,股價應該落在哪邊

例如本檔股票目前本益比是13.77

若按照目前的本益比,大致落在低本益比此區間,目前股價是27.95,可搭配K線來看進場時機

雖然分析工具很多,但是還是回歸漫步華爾街作者所說的,你無法預測未來成長與盈餘、你也無法有100%可以賺錢的分析工具、你只能降低失敗機率,這樣才能提升你賺錢的機率,故作者建議選擇低本益比的股票,勝算較高

參考資料
[1] http://www.cmoney.tw/finance/f00041.aspx?m=3&s=2034
[2] http://jsjustweb.jihsun.com.tw/z/zc/zca/zca_2034.djhtm
[3] http://www.cnyes.com/twstock/profile/2034.htm

2014/07/01

net.sf.jasperreports.engine.JRException: org.xml.sax.SAXParseException; Premature end of file.

Problem
When I try to build my project, it show this error message
1:  [ERROR] Could not compile fms435r1.jrxml because org.xml.sax.SAXParseException; Premature end of file.  
2:  net.sf.jasperreports.engine.JRException: org.xml.sax.SAXParseException; Premature end of file.  
3:       at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:247)  
4:       at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:230)  
5:       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:218)  
6:       at net.sf.jasperreports.engine.JasperCompileManager.compileToStream(JasperCompileManager.java:191)  
7:       at net.sf.jasperreports.engine.JasperCompileManager.compileReportToStream(JasperCompileManager.java:471)  
8:       at com.alexnederlof.jasperreport.CompileTask.call(CompileTask.java:65)  
9:       at com.alexnederlof.jasperreport.CompileTask.call(CompileTask.java:28)  
10:       at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)  
11:       at java.util.concurrent.FutureTask.run(FutureTask.java:166)  
12:       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
13:       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
14:       at java.lang.Thread.run(Thread.java:724)  

As I try to open this jrxml file via iReport Designer, it show the same error message


Root Cause
As I change iReport mode from Designer to XML, I figure out the root cause. This jrxml file had broken for unknown reason, it's an empty jrxml file so it cannot be compiled correctly.

THerefore, I need to revert this file to server version by svn client, and do it again.





2014/06/27

[AngularJS] How do I conditionally apply CSS styles in AngularJS?

Requirement
If the amount value of the last column is less than zero, it should be showed by red color.

Solution
Step1. create a css file, and define a pair of key and value.


Step2. add ng-class in the input text, and give a condition: 
when the value of row.amtc are less than zero, then apply negative-number css
when the value of row.amtc are equal or greater than zero, then apply nothing.
1:  <td class="text-left border-right" style="width:150px">  
2:    <input id="amtc" name="amtc" size="30" maxlength="16"  
3:        data-ng-readonly="true" ng-class="row.amtc < 0 ? 'negative-number' : ''"  
4:        data-ng-model="row.amtc" style="width:150px;text-align:right"   
5:        title="{{row.amtcf}}"/>  
6:  </td>  

Demo

2014/06 花蓮

太魯閣砂卡礑步道


夢幻湖 雲山水



林田山林業文化園區


花蓮港-麗娜輪

2014/06/26

[Oracle] Use to_char to format a number type column to currency format

Requirement

Before formatting.....
User hopes to add 1000 separator in amount-related columns, including AMT_A, AMT_B, and AMT_C
SELECT A.YEAR AS YEAR,--年度\n
       A.YYY_MM AS YYY_MM, --資料年月\n
       A.ASP, --性質別\n
       A.ITEM_CD AS ITEM_CD, --特別預算支出項目代號\n
       TRIM(A.ITEM_NM) AS ITEM_NM, --特別預算支出項目名稱\n
       F_FMS420R_GET_ACCUM_AMTA('10201', '10302', A.ASP) AS AMT_A, --實支數\n
       F_FMS420R_GET_ACCUM_AMTB('10201', '10302', A.ASP) AS AMT_B,
       --年度經費滕餘數\n
       F_FMS420R_GET_ACCUM_AMTC('10201', '10302', A.ASP) AS AMT_C --淨數\n
FROM FMS420FA A
WHERE A.YEAR = '103' AND A.YYY_MM = '10302'
ORDER BY TRIM(A.ITEM_NM) ;



Solution
We can use Oracle build-in function, TO_CHAR, to do currency format.
SELECT A.YEAR AS YEAR,--年度\n
       A.YYY_MM AS YYY_MM, --資料年月\n
       A.ASP, --性質別\n
       A.ITEM_CD AS ITEM_CD,
       --特別預算支出項目代號\n
       TRIM(A.ITEM_NM) AS ITEM_NM,
       --特別預算支出項目名稱\n
       TRIM(TO_CHAR(F_FMS420R_GET_ACCUM_AMTA('10201', '10302', A.ASP), '999,999,999,990.9999')) AS AMT_A_F,
       --實支數\n
       TRIM(TO_CHAR(F_FMS420R_GET_ACCUM_AMTB('10201', '10302', A.ASP), '999,999,999,990.9999')) AS AMT_B_F,
       --年度經費滕餘數\n
       TRIM(TO_CHAR(F_FMS420R_GET_ACCUM_AMTC('10201', '10302', A.ASP), '999,999,999,990.9999')) AS AMT_C_F --淨數\n
FROM FMS420FA A
WHERE A.YEAR = '103' AND A.YYY_MM = '10302'
ORDER BY TRIM(A.ITEM_NM) ;


2014/06/10

Parameter(s) [SPEC_FUND] are unresovlable in query string

Problem
Here has part of my SQL statement.
I faced a weird situation, this SQL statement can be executed successfully in SQL Developer, but fail to execute in Java program.

SELECT /*+USE_HASH (Y,LY,CALENDAR,LWD)*/ Y.PDATE ,
       NVL(Y.INCM_TAX,0) + NVL(LY.INCM_TAX,0) AS INCM_TAX ,
       NVL(Y.INCM_OTH,0) + NVL(LY.INCM_OTH,0) AS INCM_OTH ,
       Y.INCM_LOAN ,
       NVL(Y.INCM_NET_SALE,0) + NVL(LY.INCM_NET_SALE,0) AS INCM_NET_SALE ,
       NVL(Y.PAY_OTH,0) + NVL(LY.PAY_OTH,0) AS PAY_OTH ,
       Y.PAY_T_BILL ,
       NVL(Y.SPEC_FUND,0) - NVL(LWD.SPEC_FUND,0) AS SPEC_FUND,                        --:SPEC_FUND – ALLOT_TAX(自AVE107FB)
       NVL(Y.CHK_FUND,0) - NVL(LWD.CHK_FUND,0) AS CHK_FUND                     FROM .....

As I executed this SQL statement in Java program, it throws exception : Parameter(s) [SPEC_FUND] are unresovlable in query string

Root Cause
This problem result from ":SPEC_FUND" in remarks. 
SELECT /*+USE_HASH (Y,LY,CALENDAR,LWD)*/ Y.PDATE ,
       NVL(Y.INCM_TAX,0) + NVL(LY.INCM_TAX,0) AS INCM_TAX ,
       NVL(Y.INCM_OTH,0) + NVL(LY.INCM_OTH,0) AS INCM_OTH ,
       Y.INCM_LOAN ,
       NVL(Y.INCM_NET_SALE,0) + NVL(LY.INCM_NET_SALE,0) AS INCM_NET_SALE ,
       NVL(Y.PAY_OTH,0) + NVL(LY.PAY_OTH,0) AS PAY_OTH ,
       Y.PAY_T_BILL ,
       NVL(Y.SPEC_FUND,0) - NVL(LWD.SPEC_FUND,0) AS SPEC_FUND,                        --:SPEC_FUND – ALLOT_TAX(自AVE107FB)
                                          NVL(Y.CHK_FUND,0) - NVL(LWD.CHK_FUND,0) AS CHK_FUND                     FROM .....

Basically, program will ignore what I wrote in remarks. But I do not know why it will still interpret remarks in this case. Therefore, As I remove ":SPEC_FUND", this SQL statement will be working fine.