Mercurial > mercurial > hgweb_golang.cgi
comparison src/entai/entai.go @ 3:ca866a38a6a0
Implement intaractive-mode & setting from config-file.
author | pyon@macmini |
---|---|
date | Sun, 16 Oct 2016 09:54:33 +0900 |
parents | 451c99c1d9de |
children | 4c6bfc90d75c |
comparison
equal
deleted
inserted
replaced
2:451c99c1d9de | 3:ca866a38a6a0 |
---|---|
1 /****************************************************************************/ | 1 /****************************************************************************/ |
2 /* Entai.go ( ver 0.2 ) */ | 2 /* Entai.go ( ver 0.3 ) */ |
3 /* Last Change: 2016-10-07 Fri 18:32:08. */ | 3 /* Last Change: 2016-10-16 Sun 09:50:13. */ |
4 /* By T.Mutoh */ | |
4 /****************************************************************************/ | 5 /****************************************************************************/ |
5 | 6 |
6 package entai | 7 package entai |
7 | 8 |
8 import ( | 9 import ( |
9 "fmt" | 10 "fmt" |
11 "strconv" | |
10 "time" | 12 "time" |
11 ) | 13 ) |
12 | 14 |
13 var rate0s, rate1s []float64 | 15 var rate0s, rate1s []float64 |
14 var nyds []time.Time | 16 var nyds []time.Time |
23 paid time.Time | 25 paid time.Time |
24 am time.Time | 26 am time.Time |
25 } | 27 } |
26 | 28 |
27 func init() { | 29 func init() { |
30 } | |
31 | |
32 func ( e *Entai ) DefaultRates() { | |
28 // 1カ月まで, 1カ月経過後, 元旦 | 33 // 1カ月まで, 1カ月経過後, 元旦 |
29 createRates( 4.3, 14.6, "20120101" ) // H24 | 34 createRates( 4.3, 14.6, "20120101" ) // H24 |
30 createRates( 4.3, 14.6, "20130101" ) // H25 | 35 createRates( 4.3, 14.6, "20130101" ) // H25 |
31 createRates( 4.3, 14.6, "20140101" ) // H26 | 36 createRates( 4.3, 14.6, "20140101" ) // H26 |
32 createRates( 2.9, 9.2, "20150101" ) // H27 | 37 createRates( 2.9, 9.2, "20150101" ) // H27 |
33 createRates( 2.8, 9.1, "20160101" ) // H28 | 38 createRates( 2.8, 9.1, "20160101" ) // H28 |
34 createRates( 2.8, 9.1, "20170101" ) // H29 ***** | 39 createRates( 2.8, 9.1, "20170101" ) // H29 ***** |
40 | |
41 for range nyds { | |
42 e.yd0 = append( e.yd0, 0 ) | |
43 e.yd1 = append( e.yd1, 0 ) | |
44 } | |
35 } | 45 } |
36 | 46 |
37 func createRates( r0, r1 float64, nyd string ) { | 47 func createRates( r0, r1 float64, nyd string ) { |
38 t, _ := time.Parse( "20060102", nyd ) | 48 t, _ := time.Parse( "20060102", nyd ) |
39 rate0s = append( rate0s, r0 / 100 ) | 49 rate0s = append( rate0s, r0 / 100 ) |
40 rate1s = append( rate1s, r1 / 100 ) | 50 rate1s = append( rate1s, r1 / 100 ) |
41 nyds = append( nyds, t ) | 51 nyds = append( nyds, t ) |
42 } | 52 } |
43 | 53 |
54 func ( e *Entai ) AddRates( nyd, r0, r1 string ) error { | |
55 rf0, err := strconv.ParseFloat( r0, 64 ); if err != nil { | |
56 return err | |
57 } | |
58 rf1, err := strconv.ParseFloat( r1, 64 ); if err != nil { | |
59 return err | |
60 } | |
61 createRates( rf0, rf1, nyd ) | |
62 e.yd0 = append( e.yd0, 0 ) | |
63 e.yd1 = append( e.yd1, 0 ) | |
64 return nil | |
65 } | |
66 | |
44 func ( e Entai ) String() string { | 67 func ( e Entai ) String() string { |
45 return "Entai....." | 68 return "Entai....." |
46 } | 69 } |
47 | 70 |
48 func ( e Entai ) GetRate() string { | 71 func ( e Entai ) GetRates() string { |
49 var str string | 72 var str string |
50 for i, n := range nyds { | 73 for i, n := range nyds { |
51 str += fmt.Sprintf( " (H%d) ", n.Year() - 1988 ) | 74 str += fmt.Sprintf( " (H%d) ", n.Year() - 1988 ) |
52 str += fmt.Sprintf( "%s :%4.1f / %4.1f\n", n.Format("2006.01.02"), rate0s[i] * 100, rate1s[i] * 100 ) | 75 str += fmt.Sprintf( "%s :%4.1f / %4.1f\n", n.Format("2006.01.02"), rate0s[i] * 100, rate1s[i] * 100 ) |
53 } | 76 } |
97 break | 120 break |
98 } | 121 } |
99 } | 122 } |
100 } | 123 } |
101 | 124 |
102 func ( e *Entai ) Create() { | |
103 for range nyds { | |
104 e.yd0 = append( e.yd0, 0 ) | |
105 e.yd1 = append( e.yd1, 0 ) | |
106 } | |
107 } | |
108 | |
109 func ( e *Entai ) Set( d, p time.Time, g int ) { | 125 func ( e *Entai ) Set( d, p time.Time, g int ) { |
110 e.due, e.paid = d, p | 126 e.due, e.paid = d, p |
111 e.tax = g | 127 e.tax = g |
112 e.countDays() | 128 e.countDays() |
113 } | 129 } |
116 | 132 |
117 /* 税額の前処理 */ | 133 /* 税額の前処理 */ |
118 if e.tax < 2000 { | 134 if e.tax < 2000 { |
119 return 0, "tax < 2000" | 135 return 0, "tax < 2000" |
120 } | 136 } |
121 e.tax = int( e.tax / 1000 * 1000 ) // 端数処理 | 137 e.tax = int( e.tax / 1000 ) * 1000 // 端数処理 |
122 | 138 |
123 /* 本計算 */ | 139 /* 本計算 */ |
124 var tmp float64 | 140 var tmp float64 |
125 for i, _ := range nyds { | 141 for i, _ := range nyds { |
126 tmp += float64( e.yd0[i] ) * rate0s[i] + float64( e.yd1[i] ) * rate1s[i] | 142 tmp += float64( e.yd0[i] ) * rate0s[i] + float64( e.yd1[i] ) * rate1s[i] |