Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agrega la extracción de Efectivo en Gs. y Otros Activos #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions parser/declaration/declaration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Declaration struct {
Instituciones []*Job `json:"instituciones"`

// Activos
NetCash int64 `json:"efectivoEnGs."`
Deposits []*Deposit `json:"depositos"`
Debtors []*Debtor `json:"deudores"`
RealStates []*RealState `json:"inmuebles"`
Expand All @@ -26,6 +27,7 @@ type Declaration struct {

Debts []*Debt `json:"deudas"`


IncomeMonthly int64 `json:"ingresosMensual"`
IncomeAnnual int64 `json:"ingresosAnual"`
ExpensesMonthly int64 `json:"egresosMensual"`
Expand Down Expand Up @@ -169,5 +171,7 @@ func (d *Declaration) AddAssets() int64 {
total += v.Importe
}

total += d.NetCash

return total
}
197 changes: 0 additions & 197 deletions parser/extract/asset.go

This file was deleted.

24 changes: 24 additions & 0 deletions parser/extract/cash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package extract

import (
"strings"
)

func Cash(e *Extractor, parser *ParserData) int64 {
e.BindFlag(EXTRACTOR_FLAG_3)

if e.MoveUntilContains(CurrToken, "1. ACTIVOS"){
for e.Scan(){
if strings.Contains(e.CurrToken, "1.1 EFECTIVO EN GS."){
if isNumber(e.NextToken) {
return StringToInt64(e.NextToken)
}

}

}
}

return 0

}
143 changes: 143 additions & 0 deletions parser/extract/otherAssets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package extract

import (
"strings"
"github.com/pkg/errors"
"github.com/InstIDEA/ddjj/parser/declaration"
)

func otherAssets(e *Extractor, parser *ParserData) ([]*declaration.OtherAsset, error){

e.BindFlag(EXTRACTOR_FLAG_1)
e.BindFlag(EXTRACTOR_FLAG_2)

var assets []*declaration.OtherAsset
assets = countAssets(e, assets)

total := addAssets(assets)
if total == 0 {
return nil, errors.New("failed when extracting other assets")
}

return assets, nil
}

func countAssets(e *Extractor, assets []*declaration.OtherAsset) []*declaration.OtherAsset {
asset := &declaration.OtherAsset{ }
for e.Scan() {
if strings.Contains(e.CurrToken, "ACCIONES"){
//Cuando el nombre de la empresa tiene dos lineas, queda en PrevToken, sino queda OBS N/A o el form field y es el caso "normal"
if strings.Contains(e.PrevToken, "OBS: N/A") || isAssetFormField(e.PrevToken){
values := tokenize(e.CurrToken, 5)
//asset is added only if it has all of the needed values
if len(values) == 8 {
asset = getAsset3(values)
assets = append(assets, asset)
} else {
continue
}
}else{
//Cuando hay dos lineas, la primera linea queda en PrevToken, en CurrToken queda el indice y ACCIONES y en NextToken la segunda linea del nombre
//entonces se concatenan PrevToken y NextToken, y luego se vuelve a scanear para tener el resto de los datos
//Tambien se tiene el caso en el que el nombre se encuentra una linea mas arriba a pesar de no tener dos lineas (Ejemplo: Cartes 2018, Consignataria de Ganado S.A>)
var name string
if !strings.Contains(e.NextToken, "OBS: N/A"){
name = e.PrevToken + " " + e.NextToken
}
for i := 1; i < 3; i++ {
e.Scan()
}
//aditional values that are not in the line but are needed to have the full asset, included the name
additional := []string{"#","ACCIONES", name}
values := append(additional, tokenize(e.CurrToken, 4)...)
if len(values) == 8 {
asset = getAsset3(values)
assets = append(assets, asset)
} else {
continue
}

}
} else if strings.Contains(e.CurrToken, "CERTIFICADO DE DEPOSITOS DE"){
//subsequent scans are needed due to the document format
for i := 1; i < 4; i++ {
e.Scan()
}
//fixed values that are not in the line but are needed to have the full asset
fixed := []string{"#","CERTIFICADO DE DEPOSITOS DE AHORROS"}
values := append(fixed, tokenize(e.CurrToken, 4)...)
asset = getAsset3(values)
assets = append(assets, asset)
} else if strings.Contains(e.CurrToken, "INVERSIONES") || strings.Contains(e.CurrToken, "BONOS") || strings.Contains(e.CurrToken, "PATENTES") || (strings.Contains(e.CurrToken, "OTROS") && strings.Contains(e.NextToken, "OBS: N/A")){
values := tokenize(e.CurrToken, 5)
if len(values) == 8 {
asset = getAsset3(values)
assets = append(assets, asset)
} else {
continue
}
}else{
continue
}
}

return assets
}

/*
Function to check if a given string is or not the header of the section.
Parameter: string s
Return: True or false
*/

func isAssetFormField(s string) bool {
formField := []string {
"#",
"DESCRIPCION",
"EMPRESA",
"RUC",
"PAIS",
"CANT.",
"PRECIO UNI.",
"IMPORTE",
}

s = removeAccents(s)
for _, value := range formField {
if isCurrLine(s, value) {
return true
}
}

return false
}

/*
Function to load the extracted values into the OtherAsset structure.
Parameters: values in an array of strings. The first element is not inserted because it is the index and not relevant.
Return: an instance of OtherAsset with the values from the array
*/

func getAsset3(values []string) *declaration.OtherAsset {
return &declaration.OtherAsset{
Descripcion: values[1],
Empresa: values[2],
RUC: values[3],
Pais: values[4],
Cantidad: stringToInt64(values[5]),
Precio: stringToInt64(values[6]),
Importe: stringToInt64(values[7]),
}
}

/*
Function to calculate the total of the extracted assets.
*/

func addAssets(assets []*declaration.OtherAsset) int64 {
var total int64
for _, a := range assets {
total += a.Importe
}
return total
}
Loading