| 1 |
/* |
| 2 |
* MoneyImport : Convert Bank csv file to MS Money OFX file. |
| 3 |
* |
| 4 |
* Copyright (c) 2001-2003 Takuya Murakami. All rights reserved. |
| 5 |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without |
| 7 |
* modification, are permitted provided that the following conditions |
| 8 |
* are met: |
| 9 |
* |
| 10 |
* 1. Redistributions of source code must retain the above copyright |
| 11 |
* notice, this list of conditions and the following disclaimer. |
| 12 |
* |
| 13 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 14 |
* notice, this list of conditions and the following disclaimer in the |
| 15 |
* documentation and/or other materials provided with the distribution. |
| 16 |
* |
| 17 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 |
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR |
| 21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 22 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 23 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 24 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 25 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 26 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
* |
| 29 |
* $Id$ |
| 30 |
*/ |
| 31 |
|
| 32 |
#include <vcl.h> |
| 33 |
#pragma hdrstop |
| 34 |
#include <stdio.h> |
| 35 |
#include "Account.h" |
| 36 |
#include "Transaction.h" |
| 37 |
#include "SonyBank.h" |
| 38 |
|
| 39 |
SBAccount::SBAccount(void) |
| 40 |
{ |
| 41 |
Ident = "SonyBank"; |
| 42 |
BankName = "�\�j�[���s"; |
| 43 |
BankId = "0035"; |
| 44 |
} |
| 45 |
|
| 46 |
/* |
| 47 |
* ',' �����������������l���������� |
| 48 |
*/ |
| 49 |
static long atoi_wc(char *s) |
| 50 |
{ |
| 51 |
char buf[100], *p; |
| 52 |
|
| 53 |
p = buf; |
| 54 |
while (*s) { |
| 55 |
if (*s != ',') { |
| 56 |
*p++ = *s; |
| 57 |
} |
| 58 |
s++; |
| 59 |
} |
| 60 |
*p = '\0'; |
| 61 |
return atol(buf); |
| 62 |
} |
| 63 |
|
| 64 |
TransactionList * SBAccount::ReadFile(FILE *fp) |
| 65 |
{ |
| 66 |
TransactionList *list = new SBTransaction; |
| 67 |
if (list->ReadCsv(fp) < 0) { |
| 68 |
delete list; |
| 69 |
return NULL; |
| 70 |
} |
| 71 |
return list; |
| 72 |
} |
| 73 |
|
| 74 |
// |
| 75 |
// SB �g�����U�N�V�������X�g |
| 76 |
// |
| 77 |
|
| 78 |
Transaction *SBTransaction::GenerateTransaction(int nrows, char **rows, int *err) |
| 79 |
{ |
| 80 |
Transaction *trans = new Transaction; |
| 81 |
|
| 82 |
/* 2002�N01��01�� */ |
| 83 |
/* 01234567890123 */ |
| 84 |
char *d = rows[0]; |
| 85 |
d[4] = '\0'; d[8] = '\0'; d[12] = '\0'; |
| 86 |
trans->date.year = atoi(d); |
| 87 |
trans->date.month = atoi(d + 6); |
| 88 |
trans->date.date = atoi(d + 10); |
| 89 |
|
| 90 |
trans->date.hour = 0; |
| 91 |
trans->date.minutes = 0; |
| 92 |
trans->date.seconds = 0; |
| 93 |
|
| 94 |
/* Transaction ID ���A���t���������������������������� */ |
| 95 |
int date = trans->date.year - 1970; |
| 96 |
date = date * 12 + trans->date.month; |
| 97 |
date = date * 31 + trans->date.date; |
| 98 |
trans->id = GenerateTransactionId(date); |
| 99 |
|
| 100 |
/* Description */ |
| 101 |
trans->desc = utf8(rows[1]); |
| 102 |
|
| 103 |
if (strcmp(rows[3], "") != 0) { |
| 104 |
trans->SetTransactionType(rows[2], T_OUTGO); |
| 105 |
trans->value = - atoi_wc(rows[3]); |
| 106 |
} else { |
| 107 |
trans->SetTransactionType(rows[2], T_INCOME); |
| 108 |
trans->value = atoi_wc(rows[2]); |
| 109 |
} |
| 110 |
trans->balance = atoi_wc(rows[4]); |
| 111 |
|
| 112 |
return trans; |
| 113 |
} |