void AB_SetupNewUserDialog_Fini(GWEN_DIALOG *dlg) {
  AB_SETUP_NEWUSER_DIALOG *xdlg;
  int i;
  GWEN_DB_NODE *dbPrefs;

  assert(dlg);
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AB_SETUP_NEWUSER_DIALOG, dlg);
  assert(xdlg);

  xdlg->selectedType=0;
  free(xdlg->selectedBackend);
  xdlg->selectedBackend=NULL;
  i=AB_SetupNewUserDialog_DetermineBackendIndex(dlg);
  if (i>=0) {
    const char *s;
    GWEN_DIALOG_LIST2_ITERATOR *it;

    s=GWEN_StringList_StringAt(xdlg->backendNames, i);
    if (s && *s)
      xdlg->selectedBackend=strdup(s);

    it=GWEN_Dialog_List2_First(xdlg->backendDialogs);
    if (it) {
      int j=i;
      GWEN_DIALOG *cdlg;

      cdlg=GWEN_Dialog_List2Iterator_Data(it);
      while(cdlg && j>0) {
        j--;
	cdlg=GWEN_Dialog_List2Iterator_Next(it);
      }
      GWEN_Dialog_List2Iterator_free(it);

      if (cdlg)
	xdlg->selectedType=AB_UserTypePageDialog_GetSelectedType(cdlg);
    }
  }

  /* save dialog settings */
  dbPrefs=GWEN_Dialog_GetPreferences(dlg);

  /* store dialog width */
  i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, -1);
  GWEN_DB_SetIntValue(dbPrefs,
		      GWEN_DB_FLAGS_OVERWRITE_VARS,
		      "dialog_width",
		      i);

  /* store dialog height */
  i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, -1);
  GWEN_DB_SetIntValue(dbPrefs,
		      GWEN_DB_FLAGS_OVERWRITE_VARS,
		      "dialog_height",
		      i);
}
Exemple #2
0
int AHB_DTAUS__CreateSetC(GWEN_BUFFER *dst,
                          GWEN_DB_NODE *cfg,
                          GWEN_DB_NODE *xa,
			  AB_VALUE *sumEUR,
                          AB_VALUE *sumDEM,
                          AB_VALUE *sumBankCodes,
                          AB_VALUE *sumAccountIds){
  unsigned int i;
  const char *p;
  char buffer[32];
  int isDebitNote;
  int isEuro;
  unsigned int extSets;
  //unsigned int startPos;
  AB_VALUE *val;
  GWEN_STRINGLIST *purposeList;

  DBG_DEBUG(AQBANKING_LOGDOMAIN, "Creating C set");

  /* ______________________________________________________________________
   * preparations
   */
  purposeList=GWEN_StringList_new();
  /* cut purpose lines into manageable portions (max 27 chars) */
  for (i=0; ; i++) {
    int slen;
    GWEN_BUFFER *nbuf;

    p=GWEN_DB_GetCharValue(xa, "purpose", i, 0);
    if (p==NULL)
      break;
    if (i>14) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many purpose lines (maxmimum is 14)");
      GWEN_StringList_free(purposeList);
      return -1;
    }

    slen=strlen(p);
    nbuf=GWEN_Buffer_new(0, slen+1, 0, 1);
    AB_ImExporter_Utf8ToDta(p, -1, nbuf);
    p=GWEN_Buffer_GetStart(nbuf);

    while(*p) {
      while(*p>0 && *p<33)
	p++;
      slen=strlen(p);
      if (slen==0)
        break;
      else if (slen>27) {
	char *ns;

	ns=(char*) malloc(28);
	assert(ns);
	memmove(ns, p, 27);
	ns[27]=0;
	/* let stringlist take over ownership of the the string */
	GWEN_StringList_AppendString(purposeList, ns, 1, 0);
	p+=27;
      }
      else {
	GWEN_StringList_AppendString(purposeList, p, 0, 0);
	break;
      }
    }
    GWEN_Buffer_free(nbuf);
  } /* for */

  //startPos=GWEN_Buffer_GetPos(dst);
  GWEN_Buffer_AllocRoom(dst, 256);

  isDebitNote=(strcasecmp(GWEN_DB_GetCharValue(cfg, "type", 0, "transfer"),
                          "debitnote")==0);
  isEuro=(strcasecmp(GWEN_DB_GetCharValue(cfg, "currency", 0, "EUR"),
                     "EUR")==0);

  /* compute number of extension sets */
  extSets=0;

  /* add purpose */
  if (GWEN_StringList_Count(purposeList))
    extSets+=GWEN_StringList_Count(purposeList)-1;

  /* add name */
  for (i=1; i<2; i++) { /* max 1 extset for local name */
    if (GWEN_DB_GetCharValue(xa, "localName", i, 0)==0)
      break;
    if (i>1) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many name lines (maxmimum is 2)");
      GWEN_StringList_free(purposeList);
      return -1;
    }
    extSets++;
  } /* for */

  /* add other name */
  for (i=1; i<2; i++) { /* max 1 extset for remote name */
    if (GWEN_DB_GetCharValue(xa, "remoteName", i, 0)==0)
      break;
    if (i>1) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many peer name lines (maxmimum is 2)");
      GWEN_StringList_free(purposeList);
      return -1;
    }
    extSets++;
  } /* for */

  /* check number of extension sets */
  if (extSets>15) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many extension sets (%d)", extSets);
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* ______________________________________________________________________
   * actually write C set
   */

  /* field 1, 2: record header */
  snprintf(buffer, sizeof(buffer), "%04d", 187+(extSets*29));
  GWEN_Buffer_AppendString(dst, buffer);
  GWEN_Buffer_AppendByte(dst, 'C');

  /* field 3: acting bank code */
  if (AHB_DTAUS__AddNum(dst, 8, GWEN_DB_GetCharValue(cfg, "bankCode", 0, ""))) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 4: destination bank code */
  p=GWEN_DB_GetCharValue(xa, "remoteBankCode", 0, 0);
  if (p) {
    val=AB_Value_fromString(p);
    if (val==NULL) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad bank code");
      GWEN_StringList_free(purposeList);
      return -1;
    }
    AB_Value_AddValue(sumBankCodes, val);
    AB_Value_free(val);
    if (AHB_DTAUS__AddNum(dst, 8, p)) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
      GWEN_StringList_free(purposeList);
      return -1;
    }
  }
  else {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Peer bank code missing");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 5: destination account id */
  p=GWEN_DB_GetCharValue(xa, "remoteAccountNumber", 0, 0);
  if (p) {
    val=AB_Value_fromString(p);
    if (val==NULL) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad account id");
      GWEN_StringList_free(purposeList);
      return -1;
    }
    AB_Value_AddValue(sumAccountIds, val);
    AB_Value_free(val);
    if (AHB_DTAUS__AddNum(dst, 10, p)) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
      GWEN_StringList_free(purposeList);
      return -1;
    }
  }
  else {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Peer account id missing");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 6: internal customer number (0s for now) */
  for (i=0; i<13; i++) GWEN_Buffer_AppendByte(dst, '0');

  /* field 7a: text key */
  snprintf(buffer, sizeof(buffer), "%02d", GWEN_DB_GetIntValue(xa, "textkey", 0, isDebitNote?5:51));
  if (AHB_DTAUS__AddNum(dst, 2, buffer)) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 7b: text key extension */
  snprintf(buffer, sizeof(buffer), "%03d", GWEN_DB_GetIntValue(xa, "textkeyext", 0, 0));
  if (AHB_DTAUS__AddNum(dst, 3, buffer)) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 8: bank internal field */
  GWEN_Buffer_AppendByte(dst, ' ');

  /* field 9: value in DEM */
  if (!isEuro) {
    val=AB_Value_fromString(GWEN_DB_GetCharValue(xa, "value/value", 0, "0,0"));
    if (val==NULL || AB_Value_IsZero(val)) {
      AB_Value_free(val);
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad DEM value:");
      GWEN_StringList_free(purposeList);
      return -1;
    }
    AB_Value_AddValue(sumDEM, val);
    snprintf(buffer, sizeof(buffer), "%011.0f", AB_Value_GetValueAsDouble(val)*100.0);
    AB_Value_free(val);
    if (AHB_DTAUS__AddNum(dst, 11, buffer)) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
      GWEN_StringList_free(purposeList);
      return -1;
    }
  }
  else {
    if (AHB_DTAUS__AddNum(dst, 11, "0")) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
      GWEN_StringList_free(purposeList);
      return -1;
    }
  }

  /* field 10: local bank code */
  p=GWEN_DB_GetCharValue(xa, "localbankCode", 0, 0);
  if (!p)
    p=GWEN_DB_GetCharValue(cfg, "bankCode", 0, 0);
  if (!p) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "No local bank code");
    GWEN_StringList_free(purposeList);
    return -1;
  }
  if (AHB_DTAUS__AddNum(dst, 8, p)) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 11: local account id */
  p=GWEN_DB_GetCharValue(xa, "localAccountNumber", 0, 0);
  if (!p)
    GWEN_DB_GetCharValue(cfg, "accountId", 0, 0);
  if (!p) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "No local account number");
    GWEN_StringList_free(purposeList);
    return -1;
  }
  if (AHB_DTAUS__AddNum(dst, 10, p)) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 12: value in EUR */
  if (isEuro) {
    val=AB_Value_fromString(GWEN_DB_GetCharValue(xa, "value/value", 0, "0,0"));
    if (val==NULL || AB_Value_IsZero(val)) {
      AB_Value_free(val);
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad EUR value:");
      GWEN_StringList_free(purposeList);
      return -1;
    }
    AB_Value_AddValue(sumEUR, val);
    snprintf(buffer, sizeof(buffer), "%011.0f", AB_Value_GetValueAsDouble(val)*100.0);
    AB_Value_free(val);
    if (AHB_DTAUS__AddNum(dst, 11, buffer)) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
      GWEN_StringList_free(purposeList);
      return -1;
    }
  }
  else {
    if (AHB_DTAUS__AddNum(dst, 11, "0")) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
      GWEN_StringList_free(purposeList);
      return -1;
    }
  }

  /* field 13: blanks */
  for (i=0; i<3; i++) GWEN_Buffer_AppendByte(dst, ' ');

  /* field 14a: peer name */
  if (AHB_DTAUS__AddWord(dst, 27, GWEN_DB_GetCharValue(xa, "remoteName", 0, ""))) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 14b: blanks */
  for (i=0; i<8; i++) GWEN_Buffer_AppendByte(dst, ' ');

  /* field 15: name */
  if (AHB_DTAUS__AddWord(dst, 27, GWEN_DB_GetCharValue(xa, "localname", 0, ""))) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 16: purpose */
  p=GWEN_StringList_FirstString(purposeList);
  if (p==NULL)
    p="";
  if (AHB_DTAUS__AddWord(dst, 27, p)) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 17a: currency */
  if (isEuro)
    GWEN_Buffer_AppendByte(dst, '1');
  else
    GWEN_Buffer_AppendByte(dst, ' ');

  /* field 17b: blanks */
  for (i=0; i<2; i++) GWEN_Buffer_AppendByte(dst, ' ');

  /* field 18: number of extension sets */
  snprintf(buffer, sizeof(buffer), "%02d", extSets);
  if (AHB_DTAUS__AddNum(dst, 2, buffer)) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  if (extSets) {
    unsigned int writtenExtSets=0;

    /* now append extension sets */

    /* add peer name lines */
    for (i=1; i<2; i++) { /* max: 1 extset */
      unsigned int j;

      p=GWEN_DB_GetCharValue(xa, "remoteName", i, 0);
      if (!p)
	break;

      /* append extension set */
      GWEN_Buffer_AppendString(dst, "01");
      if (AHB_DTAUS__AddWord(dst, 27, p)) {
	DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
	GWEN_StringList_free(purposeList);
	return -1;
      }
      writtenExtSets++;

      if (writtenExtSets==2)
	/* 2 ext sets written, so we need to align "C 2.Satzabschnitt" to 128 now */
	for (j=0; j<11; j++) GWEN_Buffer_AppendByte(dst, ' ');
      else if (writtenExtSets>2 && ((writtenExtSets-2) % 4)==0)
	/* "C 3-5.Satzabschnitt" complete, align to 128 bytes */
	for (j=0; j<12; j++) GWEN_Buffer_AppendByte(dst, ' ');
    } /* for */

    /* add purpose lines */
    for (i=1; i<GWEN_StringList_Count(purposeList); i++) {
      unsigned int j;

      p=GWEN_StringList_StringAt(purposeList, i);
      if (!p)
	break;

      /* append extension set */
      GWEN_Buffer_AppendString(dst, "02");
      /* strings in the list are already in DTA charset */
      if (AHB_DTAUS__AddDtaWord(dst, 27, p)) {
	DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
	GWEN_StringList_free(purposeList);
	return -1;
      }
      writtenExtSets++;

      if (writtenExtSets==2)
	/* 2 ext sets written, so we need to align "C 2.Satzabschnitt" to 128 now */
	for (j=0; j<11; j++) GWEN_Buffer_AppendByte(dst, ' ');
      else if (writtenExtSets>2 && ((writtenExtSets-2) % 4)==0)
	/* "C 3-5.Satzabschnitt" complete, align to 128 bytes */
	for (j=0; j<12; j++) GWEN_Buffer_AppendByte(dst, ' ');
    } /* for */

    /* add name lines */
    for (i=1; i<2; i++) { /* max: 1 extset */
      unsigned int j;

      p=GWEN_DB_GetCharValue(xa, "localname", i, 0);
      if (!p)
	break;

      /* append extension set */
      GWEN_Buffer_AppendString(dst, "03");
      if (AHB_DTAUS__AddWord(dst, 27, p)) {
	DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
	GWEN_StringList_free(purposeList);
	return -1;
      }
      writtenExtSets++;

      if (writtenExtSets==2)
	/* 2 ext sets written, so we need to align "C 2.Satzabschnitt" to 128 now */
	for (j=0; j<11; j++) GWEN_Buffer_AppendByte(dst, ' ');
      else if (writtenExtSets>2 && ((writtenExtSets-2) % 4)==0)
	/* "C 3-5.Satzabschnitt" complete, align to 128 bytes */
	for (j=0; j<12; j++) GWEN_Buffer_AppendByte(dst, ' ');
    } /* for */
  }

  i=((GWEN_Buffer_GetUsedBytes(dst)+127) & ~127)-GWEN_Buffer_GetUsedBytes(dst);
  while(i--)
    GWEN_Buffer_AppendByte(dst, ' ');

  GWEN_StringList_free(purposeList);
  return 0;
}
Exemple #3
0
static int readTestData(GWEN_DIALOG *dlg)
{
  AB_CSV_EDIT_PROFILE_DIALOG *xdlg;
  GWEN_SYNCIO *sio;
  GWEN_SYNCIO *baseIo;
  GWEN_BUFFER *dbuf;
  int i;
  int ignoreLines=0;
  int rv;
  const char *delimiter;
  GWEN_BUFFER *wbuffer;
  const char *s;

  assert(dlg);
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AB_CSV_EDIT_PROFILE_DIALOG, dlg);
  assert(xdlg);

  GWEN_StringList_Clear(xdlg->columns);

  /* create file IO */
  sio=GWEN_SyncIo_File_new(xdlg->testFileName, GWEN_SyncIo_File_CreationMode_OpenExisting);
  GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ);
  baseIo=sio;

  /* create buffered IO on top of file io to allow for reading of lines below */
  sio=GWEN_SyncIo_Buffered_new(baseIo);

  dbuf=GWEN_Buffer_new(0, 1024, 0, 1);

  /* skip lines */
  ignoreLines=GWEN_Dialog_GetIntProperty(dlg, "ignoreLinesSpin", GWEN_DialogProperty_Value, 0, 0);
  i=GWEN_Dialog_GetIntProperty(dlg, "headerCheck", GWEN_DialogProperty_Value, 0, 0);
  if (i)
    ignoreLines++;

  delimiter=getCharValueFromDoubleStringsCombo(dlg, "delimiterCombo", csv_delimiters);
  if (!(delimiter && *delimiter))
    delimiter="TAB";
  if (strcasecmp(delimiter, "TAB")==0)
    delimiter="\t";
  else if (strcasecmp(delimiter, "SPACE")==0)
    delimiter=" ";

  /* open file */
  rv=GWEN_SyncIo_Connect(sio);
  if (rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
    GWEN_Buffer_free(dbuf);
    GWEN_SyncIo_free(sio);
    return rv;
  }

  for (i=0; i<ignoreLines; i++) {
    rv=GWEN_SyncIo_Buffered_ReadLineToBuffer(sio, dbuf);
    if (rv<0) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Error reading: %d", rv);
      GWEN_Buffer_free(dbuf);
      GWEN_SyncIo_Disconnect(sio);
      GWEN_SyncIo_free(sio);
      return rv;
    }
    GWEN_Buffer_Reset(dbuf);
  }

  /* read single data line */
  rv=GWEN_SyncIo_Buffered_ReadLineToBuffer(sio, dbuf);
  if (rv<0) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error reading: %d", rv);
    GWEN_Buffer_free(dbuf);
    GWEN_SyncIo_Disconnect(sio);
    GWEN_SyncIo_free(sio);
    return rv;
  }

  GWEN_Dialog_SetCharProperty(dlg, "dataEdit", GWEN_DialogProperty_Value, 0,
                              GWEN_Buffer_GetStart(dbuf), 0);

  /* we don't need the io layer any longer */
  GWEN_SyncIo_Disconnect(sio);
  GWEN_SyncIo_free(sio);

  wbuffer=GWEN_Buffer_new(0, 256, 0, 1);
  s=GWEN_Buffer_GetStart(dbuf);
  while (*s) {
    rv=GWEN_Text_GetWordToBuffer(s, delimiter, wbuffer,
                                 GWEN_TEXT_FLAGS_DEL_LEADING_BLANKS |
                                 GWEN_TEXT_FLAGS_DEL_TRAILING_BLANKS |
                                 GWEN_TEXT_FLAGS_NULL_IS_DELIMITER |
                                 GWEN_TEXT_FLAGS_DEL_QUOTES,
                                 &s);
    if (rv) {
      DBG_DEBUG(AQBANKING_LOGDOMAIN, "here (%d)", rv);
      GWEN_Buffer_free(wbuffer);
      GWEN_Buffer_free(dbuf);
      return rv;
    }
    GWEN_StringList_AppendString(xdlg->columns, GWEN_Buffer_GetStart(wbuffer), 0, 0);
    GWEN_Buffer_Reset(wbuffer);
    if (*s) {
      if (strchr(delimiter, *s))
        s++;
    }
  } /* while */
  GWEN_Buffer_free(wbuffer);

  for (i=0; i<DIALOG_MAX_COLUMNS; i++) {
    char editName[32];

    snprintf(editName, sizeof(editName)-1, "col%dDataEdit", i+1);
    s=GWEN_StringList_StringAt(xdlg->columns, i);
    if (s==NULL)
      break;
    GWEN_Dialog_SetCharProperty(dlg, editName, GWEN_DialogProperty_Value, 0, s, 0);
  }

  return 0;
}