feat(expense): import expense
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package expense
|
||||
|
||||
import (
|
||||
"nos-comptes/internal/account"
|
||||
"nos-comptes/internal/storage/dao"
|
||||
"nos-comptes/internal/storage/model"
|
||||
"nos-comptes/internal/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
@@ -35,6 +39,62 @@ func (s Service) CreateExpense(expense *Expense) error {
|
||||
return s.db.CreateExpense(expense)
|
||||
}
|
||||
|
||||
func (s Service) ProcessCSVFile(filedata [][]string, account *account.Account) error {
|
||||
switch account.Provider {
|
||||
case "caisse-epargne":
|
||||
return s.processCaisseEpargne(filedata, account)
|
||||
case "boursorama":
|
||||
return s.processBoursorama(filedata, account)
|
||||
case "bnp":
|
||||
return s.processBnp(filedata, account)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s Service) processCaisseEpargne(filedata [][]string, account *account.Account) error {
|
||||
for _, val := range filedata[4:] {
|
||||
expenseDate, err := time.Parse("02/01/06", val[0])
|
||||
if err != nil {
|
||||
utils.GetLogger().Info(err)
|
||||
continue
|
||||
}
|
||||
amount := val[3]
|
||||
typeExpense := "D"
|
||||
if amount == "" {
|
||||
amount = val[4]
|
||||
typeExpense = "C"
|
||||
}
|
||||
amountParsed, err := strconv.ParseFloat(strings.Trim(strings.ReplaceAll(amount, ",", "."), "+"), 32)
|
||||
if err != nil {
|
||||
utils.GetLogger().Info(err)
|
||||
continue
|
||||
}
|
||||
expense := &Expense{
|
||||
ExpenseEditable: ExpenseEditable{
|
||||
Value: float32(amountParsed),
|
||||
Libelle: val[2],
|
||||
TypeExpense: typeExpense,
|
||||
ExpenseDate: expenseDate,
|
||||
},
|
||||
AccountId: account.ID,
|
||||
}
|
||||
s.CreateExpense(expense)
|
||||
utils.GetLogger().Info(val)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s Service) processBoursorama(filedata [][]string, account *account.Account) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s Service) processBnp(filedata [][]string, account *account.Account) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewService(database *Database) *Service {
|
||||
return &Service{db: database}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user