diff options
| author | Patrick Spek <p.spek@tyil.nl> | 2024-12-07 18:14:15 +0100 |
|---|---|---|
| committer | Patrick Spek <p.spek@tyil.nl> | 2024-12-07 18:14:15 +0100 |
| commit | 1bad7ba1ecc4c8a4d55e8c4c964ac1ff586ec9eb (patch) | |
| tree | b98e2061fb394a8358c1ea10672917b2be95974c | |
| parent | 876a930835aa633ebf4ef3a7499cb54c9736b0fd (diff) | |
| download | firefly-importer-1bad7ba1ecc4c8a4d55e8c4c964ac1ff586ec9eb.tar.gz firefly-importer-1bad7ba1ecc4c8a4d55e8c4c964ac1ff586ec9eb.tar.bz2 | |
Drop all fields not being used in the Camt053 and Firefly objects
| -rw-r--r-- | camt053.go | 178 | ||||
| -rw-r--r-- | firefly_iii.go | 41 | ||||
| -rw-r--r-- | main.go | 14 |
3 files changed, 86 insertions, 147 deletions
@@ -8,102 +8,68 @@ import ( ) type Camt053 struct { - Document string `xml:"Document"` - XmlNs string `xml:"xmlns,attr"` - BkToCstmrStmt Camt053BkToCstmrStmt `xml:"BkToCstmrStmt"` -} - -type Camt053Acct struct { - Id Camt053Id `xml:"Id"` -} - -type Camt053Amt struct { - Ccy string `xml:"Ccy,attr"` - Value float64 `xml:",chardata"` -} - -type Camt053BookgDt struct { - Dt string `xml:"Dt"` -} - -type Camt053BkToCstmrStmt struct { - Stmt Camt053Stmt `xml:"Stmt"` -} - -type Camt053BkTxCd struct { - Domn Camt053Domn `xml:"Domn"` - Prtry Camt053Prtry `xml:"Prtry"` -} - -type Camt053Cdtr struct { - Nm string `xml:"Nm"` -} - -type Camt053CdtrAcct struct { - Id Camt053Id `xml:"Id"` -} - -type Camt053Dbtr struct { - Nm string `xml:"Nm"` -} - -type Camt053DbtrAcct struct { - Id Camt053Id `xml:"Id"` -} - -type Camt053Domn struct { - Cd string `xml:"Cd"` - Fmly Camt053Fmly `xml:"Fmly"` -} - -type Camt053Fmly struct { - Cd string `xml:"Cd"` - SubFmlyCd string `xml:"SubFmlyCd"` -} - -type Camt053Id struct { - IBAN string `xml:"IBAN"` + BkToCstmrStmt struct { + Stmt struct { + Acct struct { + Id struct { + IBAN string `xml:"IBAN"` + } `xml:"Id"` + } `xml:"Acct"` + Ntry []Camt053Ntry `xml:"Ntry"` + } `xml:"Stmt"` + } `xml:"BkToCstmrStmt"` } type Camt053Ntry struct { - NtryRef string `xml:"NtryRef"` - Amt Camt053Amt `xml:"Amt"` - CdtDbtInd string `xml:"CdtDbtInd"` - BookgDt Camt053BookgDt `xml:"BookgDt"` - NtryDtls Camt053NtryDtls `xml:"NtryDtls"` - BkTxCd Camt053BkTxCd `xml:"BkTxCd"` - AddtlNtryInf string `xml:"AddtlNtryInf"` -} - -type Camt053NtryDtls struct { - TxDtls Camt053TxDtls `xml:"TxDtls"` -} - -type Camt053Prtry struct { - Cd string `xml:"Cd"` - Issr string `xml:"Issr"` -} - -type Camt053Refs struct { - EndToEndId string `xml:"EndToEndId"` - TxId string `xml:"TxId"` -} - -type Camt053RltdPties struct { - Cdtr Camt053Cdtr `xml:"Cdtr"` - CdtrAcct Camt053CdtrAcct `xml:"CdtrAcct"` - Dbtr Camt053Dbtr `xml:"Dbtr"` - DbtrAcct Camt053DbtrAcct `xml:"DbtrAcct"` -} - -type Camt053Stmt struct { - Ntry []Camt053Ntry `xml:"Ntry"` - Acct Camt053Acct `xml:"Acct"` -} - -type Camt053TxDtls struct { - Refs Camt053Refs `xml:"Refs"` - RltdPties Camt053RltdPties `xml:"RltdPties"` + NtryRef string `xml:"NtryRef"` + Amt struct { + Ccy string `xml:"Ccy,attr"` + Value float64 `xml:",chardata"` + } `xml:"Amt"` + CdtDbtInd string `xml:"CdtDbtInd"` + BookgDt struct { + Dt string `xml:"Dt"` + } `xml:"BookgDt"` + NtryDtls struct { + TxDtls struct { + Refs struct { + EndToEndId string `xml:"EndToEndId"` + TxId string `xml:"TxId"` + } `xml:"Refs"` + RltdPties struct { + Cdtr struct { + Nm string `xml:"Nm"` + } `xml:"Cdtr"` + CdtrAcct struct { + Id struct { + IBAN string `xml:"IBAN"` + } `xml:"Id"` + } `xml:"CdtrAcct"` + Dbtr struct { + Nm string `xml:"Nm"` + } `xml:"Dbtr"` + DbtrAcct struct { + Id struct { + IBAN string `xml:"IBAN"` + } `xml:"Id"` + } `xml:"DbtrAcct"` + } `xml:"RltdPties"` + } `xml:"TxDtls"` + } `xml:"NtryDtls"` + BkTxCd struct { + Domn struct { + Cd string `xml:"Cd"` + Fmly struct { + Cd string `xml:"Cd"` + SubFmlyCd string `xml:"SubFmlyCd"` + } `xml:"Fmly"` + } `xml:"Domn"` + Prtry struct { + Cd string `xml:"Cd"` + Issr string `xml:"Issr"` + } `xml:"Prtry"` + } `xml:"BkTxCd"` + AddtlNtryInf string `xml:"AddtlNtryInf"` } // Retrieve a usable string for the description of an Ntry node @@ -119,18 +85,9 @@ func (this *Camt053Ntry) Description(doc Camt053) string { func (this *Camt053Ntry) DestinationIban(doc Camt053) string { switch this.CdtDbtInd { case "CRDT": - switch this.BkTxCd.Domn.Fmly.Cd { - case "RCDT": - return doc.BkToCstmrStmt.Stmt.Acct.Id.IBAN - } + return doc.BkToCstmrStmt.Stmt.Acct.Id.IBAN case "DBIT": - switch this.BkTxCd.Domn.Cd { - case "PMNT": - switch this.BkTxCd.Domn.Fmly.Cd { - case "ICDT": - return this.NtryDtls.TxDtls.RltdPties.CdtrAcct.Id.IBAN - } - } + return this.NtryDtls.TxDtls.RltdPties.CdtrAcct.Id.IBAN } return "" @@ -181,6 +138,11 @@ func (this *Camt053Ntry) SourceName(doc Camt053) string { switch this.CdtDbtInd { case "CRDT": switch this.BkTxCd.Domn.Fmly.Cd { + case "CCRD": + split := strings.SplitN(this.AddtlNtryInf, ">", 2) + tag := strings.TrimSpace(split[0]) + + return tag case "RCDT": return this.NtryDtls.TxDtls.RltdPties.Dbtr.Nm } @@ -188,11 +150,3 @@ func (this *Camt053Ntry) SourceName(doc Camt053) string { return "" } - -func (this *Camt053Ntry) Type(doc Camt053) string { - if this.CdtDbtInd == "CRDT" { - return "deposit" - } - - return "withdrawal" -} diff --git a/firefly_iii.go b/firefly_iii.go index 7bc3885..d41b5c4 100644 --- a/firefly_iii.go +++ b/firefly_iii.go @@ -17,10 +17,8 @@ type FireflyAccountSearch struct { } type FireflyTransactionPost struct { - //ErrorIfDuplicateHash bool `json:"error_if_duplicate_hash"` - ApplyRules bool `json:"apply_rules"` - FireWebhooks bool `json:"fire_webhooks"` - //GroupTitle string `json:"group_title"` + ApplyRules bool `json:"apply_rules"` + FireWebhooks bool `json:"fire_webhooks"` Transactions []FireflyTransaction `json:"transactions"` } @@ -33,33 +31,12 @@ type FireflyTransactionSearch struct { } type FireflyTransaction struct { - Type string `json:"type"` - Date string `json:"date"` - Amount string `json:"amount"` - Description string `json:"description"` - //Order uint `json:"order"` - //CurrencyId string `json:"currency_id"` - CurrencyCode string `json:"currency_code"` - //BudgetId string `json:"budget_id"` - //CategoryId string `json:"category_id"` - //CategoryName string `json:"category_name"` - //SourceId string `json:"source_id"` - SourceName string `json:"source_name"` - //DestinationId string `json:"destination_id"` + Type string `json:"type"` + Date string `json:"date"` + Amount string `json:"amount"` + Description string `json:"description"` + CurrencyCode string `json:"currency_code"` + SourceName string `json:"source_name"` DestinationName string `json:"destination_name"` - //Reconciled bool `json:"reconciled"` - //PiggyBankId uint `json:"piggy_bank_id"` - //PiggyBankName string `json:"piggy_bank_name"` - //BillId string `json:"bill_id"` - //BillName string `json:"bill_name"` - //Tags []string `json:"tags"` - //Notes string `json:"notes"` - //InternalReference string `json:"internal_reference"` - ExternalId string `json:"external_id"` - //ExternalUrl string `json:"external_url"` - //BookDate string `json:"book_date"` - //ProcessDate string `json:"process_date"` - //DueDate string `json:"due_date"` - //PaymentDate string `json:"payment_date"` - //InvoiceDate string `json:"invoice_date"` + ExternalId string `json:"external_id"` } @@ -53,7 +53,6 @@ func main() { // Loop over all transactions and post them to Firefly III for _, ntry := range doc.BkToCstmrStmt.Stmt.Ntry { tx := FireflyTransaction{ - Type: ntry.Type(doc), Amount: fmt.Sprintf("%.02f", ntry.Amt.Value), CurrencyCode: ntry.Amt.Ccy, ExternalId: ntry.NtryRef, @@ -119,11 +118,11 @@ func main() { } if exists { - fmt.Printf("%-6.6s (%s)\n", "⚠", "Duplicate") + fmt.Printf("%-6.6s (%s)\n", "⚠", "duplicate") continue } - // Check if the transaction is a transfer + // Set the transfer type destinationType, err := fireflyApiAccountGetTypeByName(*baseUrl, *pat, tx.DestinationName) if err != nil { fmt.Printf("%-6.6s (%s)\n", "!", err) @@ -140,6 +139,15 @@ func main() { tx.Type = "transfer" } + if tx.Type == "" { + switch ntry.CdtDbtInd { + case "CRDT": + tx.Type = "deposit" + default: + tx.Type = "withdrawal" + } + } + // Post record to Firefly if !*dry { err = fireflyApiTransactionAdd(*baseUrl, *pat, tx) |
