/** * Create a new AB_TRANSACTION, fill the values from the entry fields into it * and return it. The caller must AB_TRANSACTION_free() it when finished. */ static AB_TRANSACTION * ab_trans_fill_values(GncABTransDialog *td) { /* Fill in the user-entered values */ AB_TRANSACTION *trans = AB_Transaction_new(); AB_VALUE *value; AB_Transaction_SetLocalBankCode(trans, AB_Account_GetBankCode(td->ab_acc)); AB_Transaction_SetLocalAccountNumber( trans, AB_Account_GetAccountNumber(td->ab_acc)); AB_Transaction_SetLocalCountry(trans, "DE"); AB_Transaction_SetRemoteBankCode( trans, gtk_entry_get_text(GTK_ENTRY(td->recp_bankcode_entry))); AB_Transaction_SetRemoteAccountNumber( trans, gtk_entry_get_text(GTK_ENTRY(td->recp_account_entry))); AB_Transaction_SetRemoteCountry(trans, "DE"); AB_Transaction_AddRemoteName( trans, gtk_entry_get_text(GTK_ENTRY(td->recp_name_entry)), FALSE); AB_Transaction_AddPurpose( trans, gtk_entry_get_text(GTK_ENTRY(td->purpose_entry)), FALSE); AB_Transaction_AddPurpose( trans, gtk_entry_get_text(GTK_ENTRY(td->purpose_cont_entry)), FALSE); AB_Transaction_AddPurpose( trans, gtk_entry_get_text(GTK_ENTRY(td->purpose_cont2_entry)), FALSE); AB_Transaction_AddPurpose( trans, gtk_entry_get_text(GTK_ENTRY(td->purpose_cont3_entry)), FALSE); value = AB_Value_fromDouble(gnc_amount_edit_get_damount( GNC_AMOUNT_EDIT(td->amount_edit))); /* FIXME: Replace "EUR" by account-dependent string here. */ AB_Value_SetCurrency(value, "EUR"); AB_Transaction_SetValue(trans, value); AB_Value_free(value); /* If this is a direct debit, a textkey/ "Textschluessel"/transactionCode * different from the default has to be set. */ switch (td->trans_type) { case SINGLE_DEBITNOTE: /* AB_Transaction_SetTransactionCode (trans, 05); */ AB_Transaction_SetTextKey(trans, 05); break; default: /* AB_Transaction_SetTransactionCode (trans, 51); */ AB_Transaction_SetTextKey (trans, 51); break; } return trans; }
AB_TRANSACTION *mkSepaTransfer(AB_ACCOUNT *a, GWEN_DB_NODE *db, int expTransferType) { AB_BANKING *ab; AB_TRANSACTION *t; const char *s; int i; GWEN_TIME *d; assert(a); assert(db); ab=AB_Account_GetBanking(a); assert(ab); t=AB_Transaction_new(); AB_Banking_FillGapsInTransaction(ab, a, t); s=GWEN_DB_GetCharValue(db, "name", 0, 0); if (s && *s) AB_Transaction_SetLocalName(t, s); /* remote account */ s=GWEN_DB_GetCharValue(db, "remoteBankId", 0, 0); if (s && *s) AB_Transaction_SetRemoteBankCode(t, s); s=GWEN_DB_GetCharValue(db, "remoteAccountId", 0, 0); if (s && *s) AB_Transaction_SetRemoteAccountNumber(t, s); s=GWEN_DB_GetCharValue(db, "remoteIban", 0, 0); if (s && *s) AB_Transaction_SetRemoteIban(t, s); else { DBG_ERROR(0, "No remote IBAN given"); AB_Transaction_free(t); return NULL; } s=GWEN_DB_GetCharValue(db, "remoteBic", 0, 0); if (s && *s) AB_Transaction_SetRemoteBic(t, s); else if (strncmp(AB_Transaction_GetLocalIban(t), AB_Transaction_GetRemoteIban(t), 2)) { DBG_ERROR(0, "Remote BIC id required for international transaction"); AB_Transaction_free(t); return NULL; } for (i=0; i<10; i++) { s=GWEN_DB_GetCharValue(db, "remoteName", i, 0); if (!s) break; if (*s) AB_Transaction_AddRemoteName(t, s, 0); } if (i<1) { DBG_ERROR(0, "No remote name given"); AB_Transaction_free(t); return NULL; } /* transfer data */ for (i=0; i<20; i++) { s=GWEN_DB_GetCharValue(db, "purpose", i, 0); if (!s) break; if (*s) AB_Transaction_AddPurpose(t, s, 0); } if (i<1) { DBG_ERROR(0, "No purpose given"); AB_Transaction_free(t); return NULL; } i=GWEN_DB_GetIntValue(db, "textkey", 0, -1); if (i>0) AB_Transaction_SetTextKey(t, i); s=GWEN_DB_GetCharValue(db, "value", 0, 0); if (s && *s) { AB_VALUE *v; v=AB_Value_fromString(s); assert(v); if (AB_Value_IsNegative(v) || AB_Value_IsZero(v)) { DBG_ERROR(0, "Only positive non-zero amount allowed"); AB_Transaction_free(t); return NULL; } AB_Transaction_SetValue(t, v); AB_Value_free(v); } else { DBG_ERROR(0, "No value given"); AB_Transaction_free(t); return NULL; } /* dated transfer, SEPA debit notes */ s=GWEN_DB_GetCharValue(db, "executionDate", 0, 0); if (s && *s) { GWEN_BUFFER *dbuf; dbuf=GWEN_Buffer_new(0, 32, 0, 1); GWEN_Buffer_AppendString(dbuf, s); GWEN_Buffer_AppendString(dbuf, "-00:00"); d=GWEN_Time_fromUtcString(GWEN_Buffer_GetStart(dbuf), "YYYYMMDD-hh:mm"); GWEN_Buffer_free(dbuf); if (d==0) { DBG_ERROR(0, "Invalid execution date value \"%s\"", s); AB_Transaction_free(t); return NULL; } AB_Transaction_SetDate(t, d); GWEN_Time_free(d); } /* standing orders */ s=GWEN_DB_GetCharValue(db, "firstExecutionDate", 0, 0); if (s && *s) { GWEN_BUFFER *dbuf; dbuf=GWEN_Buffer_new(0, 32, 0, 1); GWEN_Buffer_AppendString(dbuf, s); GWEN_Buffer_AppendString(dbuf, "-00:00"); d=GWEN_Time_fromUtcString(GWEN_Buffer_GetStart(dbuf), "YYYYMMDD-hh:mm"); GWEN_Buffer_free(dbuf); if (d==0) { DBG_ERROR(0, "Invalid first execution date value \"%s\"", s); AB_Transaction_free(t); return NULL; } AB_Transaction_SetFirstExecutionDate(t, d); GWEN_Time_free(d); } s=GWEN_DB_GetCharValue(db, "lastExecutionDate", 0, 0); if (s && *s) { GWEN_BUFFER *dbuf; dbuf=GWEN_Buffer_new(0, 32, 0, 1); GWEN_Buffer_AppendString(dbuf, s); GWEN_Buffer_AppendString(dbuf, "-00:00"); d=GWEN_Time_fromUtcString(GWEN_Buffer_GetStart(dbuf), "YYYYMMDD-hh:mm"); GWEN_Buffer_free(dbuf); if (d==0) { DBG_ERROR(0, "Invalid last execution date value \"%s\"", s); AB_Transaction_free(t); return NULL; } AB_Transaction_SetLastExecutionDate(t, d); GWEN_Time_free(d); } if (expTransferType==AB_Job_TypeSepaCreateStandingOrder || expTransferType==AB_Job_TypeSepaModifyStandingOrder) { const char *s; AB_TRANSACTION_PERIOD period=AB_Transaction_PeriodUnknown; /* only needed for standing orders */ s=GWEN_DB_GetCharValue(db, "executionPeriod", 0, 0); if (s && *s) { period=AB_Transaction_Period_fromString(s); if (period==AB_Transaction_PeriodUnknown) { DBG_ERROR(0, "Invalid execution period value \"%s\"", s); AB_Transaction_free(t); return NULL; } } else { DBG_ERROR(0, "Missing execution period value"); return NULL; } AB_Transaction_SetPeriod(t, period); i=GWEN_DB_GetIntValue(db, "executionCycle", 0, -1); if (i <= 0) { DBG_ERROR(0, "Invalid execution cycle value \"%d\"", i); AB_Transaction_free(t); return NULL; } AB_Transaction_SetCycle(t, i); i=GWEN_DB_GetIntValue(db, "executionDay", 0, -1); if (i <= 0 || (period == AB_Transaction_PeriodWeekly && i > 7) || (period == AB_Transaction_PeriodMonthly && i > 30 && (i < 97 || i > 99))) { DBG_ERROR(0, "Invalid execution day value \"%d\"", i); AB_Transaction_free(t); return NULL; } AB_Transaction_SetExecutionDay(t, i); } return t; }