-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
take cost inflation index when calculating tax
- Loading branch information
1 parent
22affa2
commit 6e9df8e
Showing
11 changed files
with
124 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cii | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type CII struct { | ||
ID uint `gorm:"primaryKey" json:"id"` | ||
FinancialYear string `json:"financial_year"` | ||
CostInflationIndex uint `json:"cost_inflation_index"` | ||
} | ||
|
||
func UpsertAll(db *gorm.DB, ciis []*CII) { | ||
err := db.Transaction(func(tx *gorm.DB) error { | ||
err := tx.Exec("DELETE FROM ciis").Error | ||
if err != nil { | ||
return err | ||
} | ||
for _, cii := range ciis { | ||
err := tx.Create(cii).Error | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func GetIndex(db *gorm.DB, financialYear string) uint { | ||
var cii CII | ||
result := db.Where("financial_year = ?", financialYear).First(&cii) | ||
if result.Error != nil { | ||
log.Fatal(result.Error) | ||
} | ||
return cii.CostInflationIndex | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package india | ||
|
||
import ( | ||
"net/http" | ||
|
||
"encoding/json" | ||
"io/ioutil" | ||
|
||
"github.com/ananthakumaran/paisa/internal/model/cii" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func GetCostInflationIndex() ([]*cii.CII, error) { | ||
log.Info("Fetching Cost Inflation Index from Purified Bytes") | ||
resp, err := http.Get("https://india.purifiedbytes.com/api/cii/v2.json") | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
respBytes, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
type CII struct { | ||
FinancialYear string `json:"financial_year"` | ||
CostInflationIndex uint `json:"cost_inflation_index"` | ||
} | ||
type Result struct { | ||
Data []CII | ||
} | ||
|
||
var result Result | ||
err = json.Unmarshal(respBytes, &result) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var ciis []*cii.CII | ||
for _, s := range result.Data { | ||
c := cii.CII{FinancialYear: s.FinancialYear, CostInflationIndex: s.CostInflationIndex} | ||
ciis = append(ciis, &c) | ||
|
||
} | ||
return ciis, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters