Project

General

Profile

Revision f4a16f5b src/tools/aqbanking-cli/listbal.c

View differences:

src/tools/aqbanking-cli/listbal.c
25 25
#include <errno.h>
26 26

  
27 27

  
28
static
29
AB_ACCOUNT_STATUS *_getLastAccountStatus(AB_IMEXPORTER_ACCOUNTINFO *iea) {
30
  AB_ACCOUNT_STATUS *lastAst=0;
31
  const GWEN_TIME *lastTi=0;
32
  AB_ACCOUNT_STATUS *ast=0;
33

  
34
  ast=AB_ImExporterAccountInfo_GetFirstAccountStatus(iea);
35
  while(ast) {
36
    const GWEN_TIME *ti;
37

  
38
    if (lastAst && lastTi && (ti=AB_AccountStatus_GetTime(ast))) {
39
      if (GWEN_Time_Diff(ti, lastTi)>0) {
40
	lastAst=ast;
41
        lastTi=ti;
42
      }
43
    }
44
    else {
45
      lastAst=ast;
46
      lastTi=AB_AccountStatus_GetTime(ast);
47
    }
48
    ast=AB_AccountStatus_List_Next(ast);
49
  }
50

  
51
  return lastAst;
52
}
53

  
54

  
55 28

  
56
static
57
void _dumpBal(const AB_BALANCE *bal,
58
	      const GWEN_TIME *ti,
59
	      FILE *fd) {
29
static void _dumpBal(const AB_BALANCE *bal, FILE *fd) {
60 30
  if (bal) {
61
    const GWEN_TIME *bti;
31
    const GWEN_DATE *bdt;
62 32
    const AB_VALUE *val;
63 33
  
64
    bti=AB_Balance_GetTime(bal);
65
    if (bti==0)
66
      bti=ti;
67
    if (bti) {
34
    bdt=AB_Balance_GetDate(bal);
35
    if (bdt) {
68 36
      GWEN_BUFFER *tbuf;
69 37

  
70 38
      tbuf=GWEN_Buffer_new(0, 24, 0, 1);
71
      GWEN_Time_toString(bti, "DD.MM.YYYY\thh:mm", tbuf);
39
      GWEN_Date_toStringWithTemplate(bdt, "DD.MM.YYYY", tbuf);
72 40
      fprintf(fd, "%s\t", GWEN_Buffer_GetStart(tbuf));
73 41
      GWEN_Buffer_free(tbuf);
74 42
    }
......
304 272
    }
305 273

  
306 274
    if (matches) {
307
      AB_ACCOUNT_STATUS *ast;
275
      AB_BALANCE *bal;
308 276

  
309
      ast=_getLastAccountStatus(iea);
310
      if (ast) {
311
	const GWEN_TIME *ti;
277
      bal=AB_Balance_List_GetLatestByType(AB_ImExporterAccountInfo_GetBalanceList(iea),
278
                                          AB_Balance_TypeBooked);
279
      if (bal) {
312 280
        const char *s;
313 281

  
314 282
	fprintf(f, "Account\t");
......
329 297
	  s="";
330 298
	fprintf(f, "%s\t", s);
331 299

  
332
	ti=AB_AccountStatus_GetTime(ast);
333
	_dumpBal(AB_AccountStatus_GetBookedBalance(ast), ti, f);
334
	_dumpBal(AB_AccountStatus_GetNotedBalance(ast), ti, f);
300
	_dumpBal(bal, f);
335 301

  
336 302
        fprintf(f, "\n");
337 303
      }

Also available in: Unified diff