Total Pageviews

2015/11/30

2015/11 Travel

行天宮



淡水漁人碼頭
DSC08590

DSC08641

DSC08645

DSC08647

淡水福容飯店
DSC08601
淡水旅遊景點規劃


2015/11/29

[閱讀筆記] 鄭弘儀教你投資致富 (1/2)


  1. 工作不只是幫老闆口袋賺飽飽,也是為了創造屬於自己的資產,特別是要做你所愛,愛你所做,你才會做的認真,做的快樂
  2. 走的慢且堅持到底的人,才是真正走得快的人。堅持到底的道路看起來很遠,卻是達成目標最近的路
  3. 離開現在的工作崗位,必須不是意氣用事,也不是逃避問題,一定要清楚自己的方向,也要有所準備
  4. 對於一艘盲目航行的船來說,任何方向的風都是逆風 ( To a crazy ship all wind are contrary, George Herbert )
  5. 贏得信任必須走一段長路,且不斷接受檢驗
  6. 我今天所取得的成就,並不是說明我比前人高明多少,我只不過是站在前的肩膀眺望,自然看得遠一些罷了
  7. 你自己不可能是位全才,成功通常是由一些多才多藝的智者通力合作的結果
  8. 勇敢跨出第一步,不一定會成功,但是一定不會錯過機會。跨出去不見得有收穫,但不跨出去你永遠不會有機會
  9. 投資理財是「馬拉松競賽」,而非「百米衝刺」,比的是耐力而非爆發力
  10. 你不可能靠收入致富,你要藉由儲蓄本金的投資來致富
  11. 你不理財,財不理你。忽視理財就像忽視健康一樣,遲早會使你付出沈重的代價
  12. 靠薪水是不會致富的,假使你不懂投資理財,靠死薪水存錢養老,別說想老年想福,可能連基本生活費都會不夠用
  13. 你不知道你退休後會發生什麼事情,錢會貶值,利率會下降,這些都是風險
  14. 投資最大的錯誤,就是從不開始,因此也永遠無法退休。投資的越早,複利的迷利便越大
  15. 人的一生,如果被別人需要,就會產生自我價值和成就感
  16. 要考慮到未來不可預知的狀況,保留緊急時所需要的預備金。保險是一個社會風險共同承擔的制度,給社會無法預知的危險一個金錢上的保障。保險早一點買是比較划算的,但是不需要花太多錢在保險上,一般而言,意外險、醫療險、癌症險都是基本保障,但是要注意「住院費用」與「門診費用」的給付是否完整
  17. 近年來所盛行的儲蓄行或投資行保險需視你個人情況而定,因為每個月要繳的費用很高,而且投資型保單有一定的保險存款準備,只有一小部分能使用於投資,且獲利空間並不大
  18. 投資賺錢要行有餘力,特別要把握零負債的原則
  19. 外匯投資在台灣的可操作空間很小,沒有什麼利潤可言。因為台灣政府對外匯的正式,是一個用穩定外匯,讓商人能夠必顯得工具,中央銀行不希望外商銀行賺取外匯波動的錢,原因在於台灣是出口貿易導向型的國家。因此,外匯對於像台灣以貿易為導向的國家而言,是不容易有利潤的
  20. 債券雖然風險很小,有穩定的獲利空間,但是報酬率很低,通常在 2 ~ 5 % 左右。在不景氣的時候,隨著央行利率調降 17 次,市場利率幾乎要降到 0,代表買債券是賺錢的。但是當景氣反轉時,債券市場就會變得無利可圖
  21. 在股市群眾裡,人們的智慧不會增加,反而是愚笨程度會越積越高,而且群眾的理性程度等同於八、九歲的孩童
  22. 大起大落的每股盈餘不適合長線投資,比方說今年每股盈餘賺五元,明年卻賠了三元,此時,配了股票不但沒有填權,股價還越走越低
  23. 檢查所投資的公司是否有揭露董監酬勞和員工分紅所佔的盈餘比率,若是分紅比率過高,就要計算所買的股價是否合理
  24. 股市聽信明牌是最危險的事情,任何旁門左道的「明牌」到了散戶手中就是「廢牌」,你聽到媒體講的「新聞」其實都已經是「舊聞」
  25. 「貨幣供給」是指整個社會在某一時間所存在的貨幣數量。貨幣供給額的增減能夠反應經濟市場資金狀況的好或壞。大致來說,影響貨幣供給額的因素包含貿易逆差、經濟成長率、貨幣流通速度和物價水準等。當貿易呈現順差、經濟不斷成長、貨幣流通速度快及物價水準高,貨幣供給額就會增加,反之則減少。貨幣供給額增加快速,代表這個國家在創造金錢的能力很強;若貨幣供給額增加減速,代表這個國家掙錢能力縮水,錢越來越難賺

2015/11/19

[AngularJS] Round to at most 2 decimal places in ng-grid CellFilter

Problem
I utilize ng-grid to implement the grid as bellows:

The value of 利率 has 4 decimal places, customer ask to change to 2 decimal places.
The ng-grid definition is as following:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 $scope.itemGrid = {
            multiSelect : false,
   data : 'itemData',
            showFooter : false,
            keepLastSelected: false,
   enableColumnResize: true,
            columnDefs : [ {
                field : 'fundName',
                displayName : '借入基金專戶',
                width : '21%',
                cellClass : "text-left",
                cellFilter:'dbm035eFundFilter:row.entity.toFundName : row.entity.debtType=="B"'
            }, {
                field : 'toFundName',
                displayName : '借出基金專戶',
                width : '21%',
                cellClass : "text-left",
                cellFilter:'dbm035eFundFilter:row.entity.fundName : row.entity.debtType=="B"'
            }, {
                field : 'debtDateB',
                displayName : '調借起日',
                width : '10%',
                cellClass : "text-left",
                cellFilter:"dbm035eToStringFilter|dateFilter" 
            }, {
                field : "debtDateE",
                displayName : "調借迄日",
                width : '10%',
                cellClass : "text-left",
                cellFilter:"dbm035eToStringFilter|dateFilter" 
            }, {
                field : "debtAmt",
                displayName : "調借金額",
                width : '10%',
                cellClass : "text-right",
                cellFilter:"dbm035eAmountFilter | number"
            }, {
                field : "debtRate",
                displayName : "利率",
                width : '8%',
                cellClass : "text-right"
            }, {
                field : "remark",
                displayName : "備註",
                width : '20%',
                cellClass : "text-left"
            }
   //....
 }];


How-To
Step 1. Create a cellFilter to debtRate field
1
2
3
4
5
    app.filter('dbm035eRateFilter', function() {
        return function(input) {
            return null==input?null:(Math.round(input * 100)/100);
        };
    });

Step 2. Add this cellFilter to debtRate field
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 $scope.itemGrid = {
            multiSelect : false,
   data : 'itemData',
            showFooter : false,
            keepLastSelected: false,
   enableColumnResize: true,
            columnDefs : [ {
                field : 'fundName',
                displayName : '借入基金專戶',
                width : '21%',
                cellClass : "text-left",
                cellFilter:'dbm035eFundFilter:row.entity.toFundName : row.entity.debtType=="B"'
            }, {
                field : 'toFundName',
                displayName : '借出基金專戶',
                width : '21%',
                cellClass : "text-left",
                cellFilter:'dbm035eFundFilter:row.entity.fundName : row.entity.debtType=="B"'
            }, {
                field : 'debtDateB',
                displayName : '調借起日',
                width : '10%',
                cellClass : "text-left",
                cellFilter:"dbm035eToStringFilter|dateFilter" 
            }, {
                field : "debtDateE",
                displayName : "調借迄日",
                width : '10%',
                cellClass : "text-left",
                cellFilter:"dbm035eToStringFilter|dateFilter" 
            }, {
                field : "debtAmt",
                displayName : "調借金額",
                width : '10%',
                cellClass : "text-right",
                cellFilter:"dbm035eAmountFilter | number"
            }, {
                field : "debtRate",
                displayName : "利率",
                width : '8%',
                cellClass : "text-right",
                cellFilter:"dbm035eRateFilter" 
            }, {
                field : "remark",
                displayName : "備註",
                width : '20%',
                cellClass : "text-left"
            }
   //....
 }];

Check the result


Reference
[1] http://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-in-javascript

[iReport] How to Set Line Break in Text Field

Problem
Here is my existing report design template:

You can see the report column is dynamic.
The report, with PDF format, is generating as following:

But our customer ask to set line break between 一般政府 and (基金或法人名稱).


How-To
1. Click the textfield

2. Set Markup property to styled
3. Java code should amend as bellows:
1
2
3
4
5
6
7
    Dbm037rVo header = new Dbm037rVo();
    header.setFundName("<style>公共公司<br />(基金或法人名稱)</style>");
    header.setRate1Year(Integer.toString(Integer.valueOf(accountYr) - 2).concat(" 年度(比率)"));
    header.setRate1Year(Integer.toString(Integer.valueOf(accountYr) - 1).concat(" 年度(比率)"));
    header.setRate1Year(accountYr.concat(" 年度(比率)"));
    
    result.add(header);


Reference
[1] http://www.tutorialspoint.com/jasper_reports/jasper_report_styles.htm

How to set system properties in JBoss 6.1

Problem
I'm using JBoss 6.1, how to set system properties in JBoss?

How-to
You have two approaches to do:
Approach 1: Edit standalone.xml in [JBOSS_HOME]\standalone\configuration as bellows:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?xml version='1.0' encoding='UTF-8'?>

<server xmlns="urn:jboss:domain:1.4">

    <extensions>
        <extension module="org.jboss.as.clustering.infinispan"/>
        <extension module="org.jboss.as.connector"/>
        <extension module="org.jboss.as.deployment-scanner"/>
        <extension module="org.jboss.as.ee"/>
        <extension module="org.jboss.as.ejb3"/>
        <extension module="org.jboss.as.jaxrs"/>
        <extension module="org.jboss.as.jdr"/>
        <extension module="org.jboss.as.jmx"/>
        <extension module="org.jboss.as.jpa"/>
        <extension module="org.jboss.as.jsf"/>
        <extension module="org.jboss.as.logging"/>
        <extension module="org.jboss.as.mail"/>
        <extension module="org.jboss.as.naming"/>
        <extension module="org.jboss.as.pojo"/>
        <extension module="org.jboss.as.remoting"/>
        <extension module="org.jboss.as.sar"/>
        <extension module="org.jboss.as.security"/>
        <extension module="org.jboss.as.threads"/>
        <extension module="org.jboss.as.transactions"/>
        <extension module="org.jboss.as.web"/>
        <extension module="org.jboss.as.webservices"/>
        <extension module="org.jboss.as.weld"/>
    </extensions>

    <system-properties>
        <property name="spring.profiles.active" value="INTERNET"/>
    </system-properties>
 <!--
 ................................................
 -->

</server>

Approach 2: Log into JBoss Admin console to do configuration
Step 1: Click Profile

Step 2: Click System Properties

Step 3: Click Add button

Step 4: Fill in Name and Value, then click Save button




No matter which approach you utilize, remember to RESTART JBoss after configuration.

Reference
[1] https://docs.jboss.org/author/display/AS7/Admin+Guide#AdminGuide-SystemProperties

2015/11/16

[Oracle to SQL Server Migration] ROWNUM

Problem
We used rownum = 1 in Oracle as bellows:

If we migrate to Microsoft SQL Server, how to translate it?
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
SELECT to_char(STA_DATE, 'YYYY') - 1911 ACCOUNT_YR,
       age,
       fund_id,
       (select fund_name from dbm031fa where fund_id=dbm034fa.fund_id and rownum=1) fund_name,
       mge_type,
       IN_AMT,
       OUT_AMT,
       (IN_AMT/OUT_AMT)*100 RATIO
FROM dbm034fa
WHERE to_char(STA_DATE, 'YYYY') - 1911 BETWEEN '101' AND '103'
      AND age = '379000000A'
      AND fund_id='010401C00010'
      AND mge_type='G'

How-To
We can use TOP N to fulfill this requirement.
The SQL statement will be amended as following:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
SELECT YEAR(STA_DATE) - 1911 ACCOUNT_YR,
       age,
       fund_id,
       (select TOP 1 fund_name from dbm031fa where fund_id=dbm034fa.fund_id) fund_name,
       mge_type,
       IN_AMT,
       OUT_AMT,
       (IN_AMT/OUT_AMT)*100 RATIO
FROM dbm034fa
WHERE YEAR(STA_DATE) - 1911 BETWEEN '101' AND '103'
      AND age = '379000000A'
      AND fund_id='010401C00010'
      AND mge_type='G'


Reference
[1] http://www.w3schools.com/sql/sql_top.asp
[2] https://msdn.microsoft.com/zh-tw/library/ms189463(v=sql.120).aspx

[SQL Server] Year function

Problem
Here is my table schema in Microsoft SQL Server. If I would like to retrieve an integer that represents the year of the STA_DATE (with datetime data type).


How-To
We can use YEAR function, Microsoft SQL Server build-in function, to fulfill this requirement.
SELECT sta_date,
       year(sta_date) YEAR
FROM dbm034fa

Check the result :


Reference
[1] https://msdn.microsoft.com/en-us/library/ms186313.aspx



2015/11/05

[AngularJS] How to format a number value in ng-grid cell to two decimal places?

Problem
We are using ng-grid to implement data grid as bellows:

Our customer asks the amount column should set to two decimal places (小數點第二位).
The column definitions in this ng-grid are as following:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 columnDefs : [ {
                field : 'belongFlag',
                displayName : '分類類別',
                width : '15%',
                cellClass : "text-left",
                cellFilter:'dbm034eBelongFilter:row.entity.mgeType'
            }, {
                field : "ageTypeName",
                displayName : '基金法人類別',
                width : '20%',
                cellClass : "text-left"
            }
            , {
                field : 'fundName',
                displayName : '基金法人名稱',
                width : '20%',
                cellClass : "text-left"
            }, {
                field : 'rate2Year',
                displayName : ($scope.model.year * 1 - 2) + '年度',
                width : '10%',
                cellClass : "text-right"
            }, {
                field : "rate1Year",
                displayName : ($scope.model.year * 1 - 1) + '年度',
                width : '10%',
                cellClass : "text-right"
            }, {
                field : "rate",
                displayName : ($scope.model.year * 1) + '年度',
                width : '10%',
                cellClass : "text-right"
            }, {
                field : "ageType",
                displayName : 'ageType',
                width : '0%',
                cellClass : "text-right",
                visable : false
            }
            ]


How-To
Set cellFiter to amount fields as bellows can fulfill this requirement:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 columnDefs : [ {
                field : 'belongFlag',
                displayName : '分類類別',
                width : '15%',
                cellClass : "text-left",
                cellFilter:'dbm034eBelongFilter:row.entity.mgeType'
            }, {
                field : "ageTypeName",
                displayName : '基金法人類別',
                width : '20%',
                cellClass : "text-left"
            }
            , {
                field : 'fundName',
                displayName : '基金法人名稱',
                width : '20%',
                cellClass : "text-left"
            }, {
                field : 'rate2Year',
                displayName : ($scope.model.year * 1 - 2) + '年度',
                width : '10%',
                cellClass : "text-right",
                cellFilter:'number:2'
            }, {
                field : "rate1Year",
                displayName : ($scope.model.year * 1 - 1) + '年度',
                width : '10%',
                cellClass : "text-right",
                cellFilter:'number:2'
            }, {
                field : "rate",
                displayName : ($scope.model.year * 1) + '年度',
                width : '10%',
                cellClass : "text-right",
                cellFilter:'number:2'
            }, {
                field : "ageType",
                displayName : 'ageType',
                width : '0%',
                cellClass : "text-right",
                visable : false
            }
            ]

Check the result


Reference
[1] http://stackoverflow.com/questions/30382666/how-to-format-a-number-value-in-angularjs-ui-grid-cell-to-two-decimal

2015/11/03

[iReport] How to remove extra row and column when export to excel file

Problem
When I export report with excel format via iReport/JasperReports, the excel file always has extra blank row and extra blank column as following:

User asked to remove the unnecessary row and column. 

How-to
Add two properties to this jrxml file, and set to true

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="dbm506r1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d1c3bf81-aa19-4e0e-ad82-0a34f472e482">
 <property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
 <property name="ireport.zoom" value="1.3310000000000004"/>
 <property name="ireport.x" value="0"/>
 <property name="ireport.y" value="0"/>
 <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/>
 <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>

Check the result:



Reference
[1] http://stackoverflow.com/questions/8354126/ireport-jasperreports-extra-row-issue

2015/11/02

[iReport] How to format numeric data with Excel exporter

Problem
We use JasperReports API to export report with xls format.
But the problem is : data is numeric type, but in formula area its has been applied 1000 separator. It is String data type, no numeric data type.

We provide List of value object for this iReport file. The attributes of value object is as bellows (amount-related attributes' data type had been set to BigDecimal):
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
@Data
public class Dbm506rVo implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    /** 年度 */
    private int year = 0;
    private String staYear = "";
    private BigDecimal gdp = BigDecimal.ZERO;
    private BigDecimal capitalAmount = BigDecimal.ZERO;
    private BigDecimal interestAmount = BigDecimal.ZERO;
    private BigDecimal yearExpend = BigDecimal.ZERO;
    private BigDecimal ttlAmt = BigDecimal.ZERO;
    private BigDecimal percentage1 = BigDecimal.ZERO;
    private BigDecimal percentage2 = BigDecimal.ZERO;
}


How-to
Set net.sf.jasperreports.export.xls.detect.cell.type to true (the default value is false) in this jrxml file.

Quote from document: Property whose value is used as default state of the IS_DETECT_CELL_TYPE export flag. Specifies whether the exporter should take into consideration the type of the original text field expressions and set the cell types and values accordingly.

1
2
3
4
5
6
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="dbm506r1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d1c3bf81-aa19-4e0e-ad82-0a34f472e482">
 <property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
 <property name="ireport.zoom" value="1.3310000000000004"/>
 <property name="ireport.x" value="0"/>
 <property name="ireport.y" value="0"/>



The problem will be solved:

Reference
[1] http://stackoverflow.com/questions/10714709/jasperreports-how-to-format-numeric-data-with-excel-exporter