Project

General

Profile

Revision f4a16f5b src/libs/plugins/backends/aqhbci/ajobs/jobgetbalance.c

View differences:

src/libs/plugins/backends/aqhbci/ajobs/jobgetbalance.c
113 113

  
114 114
/* --------------------------------------------------------------- FUNCTION */
115 115
AB_BALANCE *AH_Job_GetBalance__ReadBalance(GWEN_DB_NODE *dbT) {
116
  GWEN_BUFFER *buf;
117
  GWEN_TIME *t;
118
  AB_VALUE *v1, *v2;
119
  AB_BALANCE *bal;
116
  AB_VALUE *v;
120 117
  const char *p;
118
  AB_BALANCE *bal;
119
  int isCredit=0;
121 120

  
122
  bal=0;
121
  bal=AB_Balance_new();
122

  
123
  /* get isCredit */
124
  p=GWEN_DB_GetCharValue(dbT, "debitMark", 0, 0);
125
  if (p) {
126
    if (strcasecmp(p, "D")==0 ||
127
	strcasecmp(p, "RC")==0) {
128
      isCredit=0;
129
    }
130
    else if (strcasecmp(p, "C")==0 ||
131
	     strcasecmp(p, "RD")==0)
132
      isCredit=1;
133
    else {
134
      DBG_ERROR(AQHBCI_LOGDOMAIN, "Bad debit mark \"%s\"", p);
135
      AB_Balance_free(bal);
136
      return NULL;
137
    }
138
  }
123 139

  
124
  /* read date and time */
125
  buf=GWEN_Buffer_new(0, 32, 0, 1);
140
  /* read date */
126 141
  p=GWEN_DB_GetCharValue(dbT, "date", 0, 0);
127
  if (p)
128
    GWEN_Buffer_AppendString(buf, p);
129
  else {
130
    AH_AccountJob_AddCurrentDate(buf);
142
  if (p) {
143
    GWEN_DATE *dt;
144

  
145
    dt=GWEN_Date_fromStringWithTemplate(p, "YYYYMMDD");
146
    if (dt) {
147
      AB_Balance_SetDate(bal, dt);
148
      GWEN_Date_free(dt);
149
    }
150
    else {
151
      DBG_ERROR(AQHBCI_LOGDOMAIN, "Bad date \"%s\"", p);
152
      AB_Balance_free(bal);
153
      return NULL;
154
    }
131 155
  }
132
  p=GWEN_DB_GetCharValue(dbT, "time", 0, 0);
133
  if (p)
134
    GWEN_Buffer_AppendString(buf, p);
135 156
  else {
136
    AH_AccountJob_AddCurrentTime(buf);
137
  }
138
  t=GWEN_Time_fromString(GWEN_Buffer_GetStart(buf), "YYYYMMDDhhmmss");
139
  if (!t) {
140
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Error parsing date and time");
157
    GWEN_DATE *dt;
158

  
159
    DBG_WARN(AQHBCI_LOGDOMAIN, "No date, using current date");
160
    dt=GWEN_Date_CurrentDate();
161
    assert(dt);
162
    AB_Balance_SetDate(bal, dt);
163
    GWEN_Date_free(dt);
141 164
  }
142
  GWEN_Buffer_free(buf);
143 165

  
144
  /* read value */
145
  v1=AB_Value_fromDb(dbT);
146
  v2=0;
147
  if (!v1) {
166
  /* get value */
167
  v=AB_Value_fromDb(dbT);
168
  if (!v) {
148 169
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Error parsing value from DB");
170
    AB_Balance_free(bal);
171
    return NULL;
149 172
  }
150 173
  else {
151
    p=GWEN_DB_GetCharValue(dbT, "debitMark", 0, 0);
152
    if (p) {
153
      if (strcasecmp(p, "D")==0 ||
154
	  strcasecmp(p, "RC")==0) {
155
	v2=AB_Value_dup(v1);
156
	AB_Value_Negate(v2);
157
      }
158
      else if (strcasecmp(p, "C")==0 ||
159
               strcasecmp(p, "RD")==0)
160
	v2=AB_Value_dup(v1);
161
      else {
162
	DBG_ERROR(AQHBCI_LOGDOMAIN, "Bad debit mark \"%s\"", p);
163
	v2=0;
164
      }
165
    }
166
    if (v2) {
167
      bal=AB_Balance_new();
168
      AB_Balance_SetTime(bal, t);
169
      AB_Balance_SetValue(bal, v2);
170
    }
171
    else
172
      bal=NULL;
173
  }
174
    if (!isCredit)
175
      AB_Value_Negate(v);
174 176

  
175
  AB_Value_free(v2);
176
  AB_Value_free(v1);
177
  GWEN_Time_free(t);
177
    AB_Balance_SetValue(bal, v);
178
    AB_Value_free(v);
179
  }
178 180

  
179 181
  return bal;
180 182
}
......
357 359
      return rv;
358 360
    }
359 361

  
360
    dbBalance=GWEN_DB_GetGroup(dbCurr, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
361
                               "data/balance");
362
    dbBalance=GWEN_DB_GetGroup(dbCurr, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "data/balance");
362 363
    if (!dbBalance)
363
      dbBalance=GWEN_DB_GetGroup(dbCurr, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
364
                                         "data/balancecreditcard");
364
      dbBalance=GWEN_DB_GetGroup(dbCurr, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "data/balancecreditcard");
365 365
    if (dbBalance) {
366
      AB_ACCOUNT_STATUS *acst;
367 366
      GWEN_DB_NODE *dbT;
368 367
      AB_ACCOUNT *a;
369 368
      AB_IMEXPORTER_ACCOUNTINFO *ai;
......
372 371
      if (GWEN_Logger_GetLevel(0)>=GWEN_LoggerLevel_Debug)
373 372
        GWEN_DB_Dump(dbBalance, 2);
374 373

  
375
      acst=AB_AccountStatus_new();
374
      a=AH_AccountJob_GetAccount(j);
375
      assert(a);
376
      ai=AB_ImExporterContext_GetOrAddAccountInfo(ctx,
377
						  AB_Account_GetUniqueId(a),
378
						  AB_Account_GetIban(a),
379
						  AB_Account_GetBankCode(a),
380
						  AB_Account_GetAccountNumber(a),
381
						  AB_Account_GetAccountType(a));
382
      assert(ai);
383

  
376 384

  
377 385
      /* read booked balance */
378
      dbT=GWEN_DB_GetGroup(dbBalance, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
379
                           "booked");
386
      dbT=GWEN_DB_GetGroup(dbBalance, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "booked");
380 387
      if (dbT) {
381 388
        AB_BALANCE *bal;
382 389

  
383 390
        bal=AH_Job_GetBalance__ReadBalance(dbT);
384 391
        if (bal) {
385
	  AB_AccountStatus_SetBookedBalance(acst, bal);
386
	  AB_AccountStatus_SetTime(acst, AB_Balance_GetTime(bal));
387
          AB_Balance_free(bal);
392
	  AB_Balance_SetType(bal, AB_Balance_TypeBooked);
393
	  AB_ImExporterAccountInfo_AddBalance(ai, bal);
388 394
        }
389 395
      }
390 396

  
391 397
      /* read noted balance */
392
      dbT=GWEN_DB_GetGroup(dbBalance, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
393
                           "noted");
398
      dbT=GWEN_DB_GetGroup(dbBalance, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "noted");
394 399
      if (dbT) {
395 400
        AB_BALANCE *bal;
396 401

  
397 402
        bal=AH_Job_GetBalance__ReadBalance(dbT);
398 403
        if (bal) {
399
	  AB_AccountStatus_SetNotedBalance(acst, bal);
400
	  if (AB_AccountStatus_GetTime(acst)==NULL)
401
	    AB_AccountStatus_SetTime(acst, AB_Balance_GetTime(bal));
402
          AB_Balance_free(bal);
403
        }
404
	  AB_Balance_SetType(bal, AB_Balance_TypeNoted);
405
	  AB_ImExporterAccountInfo_AddBalance(ai, bal);
406
	}
404 407
      }
405 408

  
409
#if 0
406 410
      /* read credit Line */
407
      dbT=GWEN_DB_GetGroup(dbBalance, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
408
                           "creditLine");
411
      dbT=GWEN_DB_GetGroup(dbBalance, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "creditLine");
409 412
      if (dbT) {
410 413
        AB_VALUE *v;
411 414

  
......
418 421
        }
419 422
        AB_Value_free(v);
420 423
      }
424
#endif
421 425

  
422
      a=AH_AccountJob_GetAccount(j);
423
      assert(a);
424
      ai=AB_ImExporterContext_GetOrAddAccountInfo(ctx,
425
                                                  AB_Account_GetUniqueId(a),
426
                                                  AB_Account_GetIban(a),
427
                                                  AB_Account_GetBankCode(a),
428
                                                  AB_Account_GetAccountNumber(a),
429
                                                  AB_Account_GetAccountType(a));
430
      assert(ai);
431

  
432
      /* add new account status */
433
      AB_ImExporterAccountInfo_AddAccountStatus(ai, acst);
434 426
      break; /* break loop, we found the balance */
435 427
    } /* if "Balance" */
436 428

  

Also available in: Unified diff