Esempio n. 1
0
static gboolean
gettrans_dates(GtkWidget *parent, Account *gnc_acc,
               GWEN_TIME **from_date, GWEN_TIME **to_date)
{
    Timespec last_timespec, until_timespec;
    time_t now = time(NULL);
    gboolean use_last_date = TRUE;
    gboolean use_earliest_date = TRUE;
    gboolean use_until_now = TRUE;

    g_return_val_if_fail(from_date && to_date, FALSE);

    /* Get time of last retrieval */
    last_timespec = gnc_ab_get_account_trans_retrieval(gnc_acc);
    if (last_timespec.tv_sec == 0)
    {
        use_last_date = FALSE;
        timespecFromTime_t(&last_timespec, now);
    }
    timespecFromTime_t(&until_timespec, now);

    /* Let the user choose the date range of retrieval */
    if (!gnc_ab_enter_daterange(parent, NULL,
                                &last_timespec,
                                &use_last_date, &use_earliest_date,
                                &until_timespec, &use_until_now))
        return FALSE;

    /* Now calculate from date */
    if (use_earliest_date)
    {
        *from_date = NULL;
    }
    else
    {
        if (use_last_date)
            last_timespec = gnc_ab_get_account_trans_retrieval(gnc_acc);
        *from_date = GWEN_Time_fromSeconds(timespecToTime_t(last_timespec));
    }

    /* Now calculate to date */
    if (use_until_now)
        timespecFromTime_t(&until_timespec, now);
    *to_date = GWEN_Time_fromSeconds(timespecToTime_t(until_timespec));

    return TRUE;
}
Esempio n. 2
0
GWEN_TIME *GWEN_Time_new(int year,
                         int month,
                         int day,
                         int hour,
                         int min,
                         int sec,
                         int inUtc) {
  uint32_t s;

  if (inUtc)
    s=GWEN_Time__mktimeUtc(year, month, day, hour, min, sec);
  else {
    struct tm ti;
    struct tm *tp;
    time_t tt;

    tt=time(0);
    tp=localtime(&tt);
    assert(tp);
    memmove(&ti, tp, sizeof(ti));
    ti.tm_sec=sec;
    ti.tm_min=min;
    ti.tm_hour=hour;
    if (year<100) {
      if (year<72)
        year+=2000;
      year+=1900;
    }
    ti.tm_year=year-1900;
    ti.tm_mon=month;
    ti.tm_mday=day;
    ti.tm_yday=0;
    ti.tm_wday=0;
    tt=mktime(&ti);
    assert(tt!=(time_t)-1);
    s=(uint32_t)tt;
  }
  return GWEN_Time_fromSeconds(s);
}
Esempio n. 3
0
int AH_ImExporterOFX_TransactionCallback_cb(const struct OfxTransactionData data,
                                            void *user_data)
{
  AH_IMEXPORTER_OFX *ieh;

  DBG_INFO(AQBANKING_LOGDOMAIN,
           "Transaction callback");
  ieh=(AH_IMEXPORTER_OFX *)user_data;

  if (!ieh->lastAccountInfo) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Transaction but no account. Ignoring");
    return -1;
  }
  else {
    AB_TRANSACTION *t;

    t=AB_Transaction_new();
    if (data.account_id_valid)
      AB_Transaction_SetLocalAccountNumber(t, data.account_id);
    else
      AB_Transaction_SetLocalAccountNumber(t, "----");

    if (data.date_posted_valid) {
      GWEN_TIME *ti;

      ti=GWEN_Time_fromSeconds(data.date_posted);
      AB_Transaction_SetValutaDate(t, ti);
      GWEN_Time_free(ti);
    }

    if (data.date_initiated_valid) {
      GWEN_TIME *ti;

      ti=GWEN_Time_fromSeconds(data.date_initiated);
      AB_Transaction_SetDate(t, ti);
      GWEN_Time_free(ti);
    }

    if (data.fi_id_valid)
      AB_Transaction_SetFiId(t, data.fi_id);

    if (data.name_valid)
      AB_Transaction_AddRemoteName(t, data.name, 0);
    if (data.memo_valid)
      AB_Transaction_AddPurpose(t, data.memo, 0);

    if (data.amount_valid) {
      AB_VALUE *val;
      const char *cur;

      cur=0;
      if (data.account_ptr)
        if (data.account_ptr->currency_valid)
          cur=data.account_ptr->currency;
      val=AB_Value_fromDouble(data.amount);
      assert(val);
      AB_Value_SetCurrency(val, cur);
      if (data.invtransactiontype_valid)
        /* negate for investment transaction type (hack, see KMyMoney) */
        AB_Value_Negate(val);
      AB_Transaction_SetValue(t, val);
      AB_Value_free(val);
    }
    else {
      DBG_ERROR(AQBANKING_LOGDOMAIN,
                "No amount in transaction");
    }

    if (data.transactiontype_valid) {
      switch (data.transactiontype) {
      case OFX_CHECK:
        AB_Transaction_SetTransactionKey(t, "CHK");
        AB_Transaction_SetTransactionText(t, "Check");
        break;
      case OFX_INT:
        AB_Transaction_SetTransactionKey(t, "INT");
        AB_Transaction_SetTransactionText(t, "Interest");
        break;
      case OFX_DIV:
        AB_Transaction_SetTransactionKey(t, "DIV");
        AB_Transaction_SetTransactionText(t, "Dividend");
        break;
      case OFX_SRVCHG:
        AB_Transaction_SetTransactionKey(t, "CHG");
        AB_Transaction_SetTransactionText(t, "Service charge");
        break;
      case OFX_FEE:
        AB_Transaction_SetTransactionKey(t, "BRF");
        AB_Transaction_SetTransactionText(t, "Fee");
        break;
      case OFX_DEP:
        AB_Transaction_SetTransactionKey(t, "LDP"); /* FIXME: not sure */
        AB_Transaction_SetTransactionText(t, "Deposit");
        break;
      case OFX_ATM:
        AB_Transaction_SetTransactionKey(t, "MSC"); /* misc */
        AB_Transaction_SetTransactionText(t, "Cash dispenser");
        break;
      case OFX_POS:
        AB_Transaction_SetTransactionKey(t, "MSC"); /* misc */
        AB_Transaction_SetTransactionText(t, "Point of sale");
        break;
      case OFX_XFER:
        AB_Transaction_SetTransactionKey(t, "TRF");
        AB_Transaction_SetTransactionText(t, "Transfer");
        break;
      case OFX_PAYMENT:
        AB_Transaction_SetTransactionKey(t, "TRF"); /* FIXME: not sure */
        AB_Transaction_SetTransactionText(t, "Electronic payment");
        break;
      case OFX_CASH:
        AB_Transaction_SetTransactionKey(t, "MSC"); /* FIXME: not sure */
        AB_Transaction_SetTransactionText(t, "Cash");
        break;
      case OFX_DIRECTDEP:
        AB_Transaction_SetTransactionKey(t, "LDP"); /* FIXME: not sure */
        AB_Transaction_SetTransactionText(t, "Direct deposit");
        break;
      case OFX_DIRECTDEBIT:
        AB_Transaction_SetTransactionKey(t, "MSC"); /* FIXME: not sure */
        AB_Transaction_SetTransactionText(t, "Merchant initiated debit");
        break;
      case OFX_REPEATPMT:
        AB_Transaction_SetTransactionKey(t, "STO");
        AB_Transaction_SetTransactionText(t, "Standing order");
        break;
      case OFX_DEBIT:
      case OFX_CREDIT:
      case OFX_OTHER:
        AB_Transaction_SetTransactionKey(t, "MSC"); /* FIXME: not sure */
        break;
      }
    } /* if transaction type is valid */
    else if (data.invtransactiontype_valid) {
      switch (data.invtransactiontype) {
      case OFX_BUYDEBT:
      case OFX_BUYMF:
      case OFX_BUYOPT:
      case OFX_BUYOTHER:
      case OFX_BUYSTOCK:
        AB_Transaction_SetTransactionKey(t, "BUY");
        AB_Transaction_SetTransactionText(t, "Buy stocks or alike");
        AB_Transaction_SetSubType(t, AB_Transaction_SubTypeBuy);
        break;
      case OFX_REINVEST:
        AB_Transaction_SetTransactionKey(t, "REINV");
        AB_Transaction_SetTransactionText(t, "Reinvestment");
        AB_Transaction_SetSubType(t, AB_Transaction_SubTypeReinvest);
        break;
      case OFX_SELLDEBT:
      case OFX_SELLMF:
      case OFX_SELLOPT:
      case OFX_SELLOTHER:
      case OFX_SELLSTOCK:
        AB_Transaction_SetTransactionKey(t, "BUY");
        AB_Transaction_SetTransactionText(t, "Buy stocks or alike");
        AB_Transaction_SetSubType(t, AB_Transaction_SubTypeSell);
        break;
      case OFX_INCOME:
        AB_Transaction_SetTransactionKey(t, "DIV");
        AB_Transaction_SetTransactionText(t, "Dividend");
        AB_Transaction_SetSubType(t, AB_Transaction_SubTypeDividend);
        break;
      /* rest is unhandled */
      case OFX_CLOSUREOPT:
        AB_Transaction_SetTransactionText(t, "XCLOSUREOPT");
        break;
      case OFX_INVEXPENSE:
        AB_Transaction_SetTransactionText(t, "XINVEXPENSE");
        break;
      case OFX_JRNLFUND:
        AB_Transaction_SetTransactionText(t, "XJRNLFUND");
        break;
      case OFX_MARGININTEREST:
        AB_Transaction_SetTransactionText(t, "XMARGININTEREST");
        break;
      case OFX_RETOFCAP:
        AB_Transaction_SetTransactionText(t, "XRETOFCAP");
        break;
      case OFX_SPLIT:
        AB_Transaction_SetTransactionText(t, "XSPLIT");
        break;
      case OFX_TRANSFER:
        AB_Transaction_SetTransactionText(t, "XTRANSFER");
        break;
      default:
        break;
      }

#ifdef HAVE_OFX_0_8_PLUS
      if (data.fees_valid || data.commission_valid) {
        AB_VALUE *vFees;

        vFees=AB_Value_new();
        if (data.fees_valid) {
          AB_VALUE *v;

          v=AB_Value_fromDouble(data.fees);
          AB_Value_AddValue(vFees, v);
          AB_Value_free(v);
        }
        if (data.commission_valid) {
          AB_VALUE *v;

          v=AB_Value_fromDouble(data.commission);
          AB_Value_AddValue(vFees, v);
          AB_Value_free(v);
        }
        AB_Transaction_SetFees(t, vFees);
        AB_Value_free(vFees);
      }
#endif

      if (data.units_valid)
        AB_Transaction_SetUnits(t, data.units);
#ifdef HAVE_OFX_0_8_PLUS
      if (data.unitprice_valid && data.fees_valid) {
        AB_VALUE *v;

        v=AB_Value_fromDouble(data.fees); /* TODO: add currency */
        AB_Transaction_SetUnitPrice(t, v);
        AB_Value_free(v);
      }
#endif
    }
    else {
      DBG_NOTICE(AQBANKING_LOGDOMAIN, "No transaction type");
    }

    if (data.server_transaction_id_valid)
      AB_Transaction_SetBankReference(t, data.server_transaction_id);

    if (data.check_number_valid)
      AB_Transaction_SetCustomerReference(t, data.check_number);
    else if (data.reference_number_valid)
      AB_Transaction_SetCustomerReference(t, data.reference_number);

    DBG_INFO(0, "Adding transaction");
    AB_ImExporterAccountInfo_AddTransaction(ieh->lastAccountInfo, t);
  }

  return 0;

}