| 1 |
/* |
| 2 |
* FeliCa2Money |
| 3 |
* |
| 4 |
* Copyright (C) 2001-2007 Takuya Murakami |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 |
*/ |
| 20 |
//--------------------------------------------------------------------------- |
| 21 |
|
| 22 |
#include <vcl.h> |
| 23 |
#pragma hdrstop |
| 24 |
#include <Registry.hpp> |
| 25 |
|
| 26 |
#include <shellapi.h> |
| 27 |
|
| 28 |
#include <stdio.h> |
| 29 |
#include <stdlib.h> |
| 30 |
#include <string.h> |
| 31 |
|
| 32 |
#include <iostream> |
| 33 |
#include <iomanip> |
| 34 |
|
| 35 |
using namespace std; |
| 36 |
|
| 37 |
#include "MainForm.h" |
| 38 |
#include "Convert.h" |
| 39 |
#include "Card.h" |
| 40 |
#include "Transaction.h" |
| 41 |
|
| 42 |
/** |
| 43 |
@brief �R���o�[�g���s |
| 44 |
@param[in] card ���������� Card |
| 45 |
@param[out] ofxfile �����o�����s�� OFX �t�@�C���� |
| 46 |
|
| 47 |
�J�[�h���������������AOFX �t�@�C���������o�� |
| 48 |
*/ |
| 49 |
void Converter::Convert(Card *c, AnsiString ofxfile) |
| 50 |
{ |
| 51 |
card = c; |
| 52 |
|
| 53 |
// CSV �t�@�C�������� |
| 54 |
int ret = card->ReadCard(); |
| 55 |
|
| 56 |
if (ret) { |
| 57 |
Application->MessageBox("�J�[�h����������������������������", "�G���[", MB_OK); |
| 58 |
return; |
| 59 |
} |
| 60 |
if (!card->hasAnyTransaction()) { |
| 61 |
Application->MessageBox("����������������������", "�G���[", MB_OK); |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
// OFX �t�@�C���������o�� |
| 66 |
ofstream ofs(ofxfile.c_str()); |
| 67 |
if (!ofs) { |
| 68 |
Application->MessageBox("OFX�t�@�C�����J��������", "�G���[", MB_OK); |
| 69 |
return; |
| 70 |
} |
| 71 |
WriteOfx(ofs); |
| 72 |
ofs.close(); |
| 73 |
|
| 74 |
// Money �N�� |
| 75 |
ShellExecute(NULL, "open", ofxfile.c_str(), |
| 76 |
NULL, NULL, SW_SHOW); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
@brief OFX �t�@�C�������o�� |
| 81 |
@param[in] ofs �o���X�g���[�� |
| 82 |
*/ |
| 83 |
void Converter::WriteOfx(ofstream& ofs) |
| 84 |
{ |
| 85 |
unsigned long idoffset; |
| 86 |
vector<Transaction*>::iterator begin, last; |
| 87 |
|
| 88 |
begin = card->begin(); |
| 89 |
last = card->end(); |
| 90 |
last--; |
| 91 |
|
| 92 |
AnsiString beginDate = dateStr((*begin)->date); |
| 93 |
AnsiString endDate = dateStr((*last)->date); |
| 94 |
|
| 95 |
/* OFX �w�b�_ */ |
| 96 |
ofs << "OFXHEADER:100" << endl; |
| 97 |
ofs << "DATA:OFXSGML" << endl; |
| 98 |
ofs << "VERSION:102" << endl; |
| 99 |
ofs << "SECURITY:NONE" << endl; |
| 100 |
ofs << "ENCODING:UTF-8" << endl; |
| 101 |
ofs << "CHARSET:CSUNICODE" << endl; |
| 102 |
ofs << "COMPRESSION:NONE" << endl; |
| 103 |
ofs << "OLDFILEUID:NONE" << endl; |
| 104 |
ofs << "NEWFILEUID:NONE" << endl; |
| 105 |
ofs << endl; |
| 106 |
|
| 107 |
/* ���Z�@������(�T�C���I�����X�|���X) */ |
| 108 |
ofs << "<OFX>" << endl; |
| 109 |
ofs << "<SIGNONMSGSRSV1>" << endl; |
| 110 |
ofs << "<SONRS>" << endl; |
| 111 |
ofs << " <STATUS>" << endl; |
| 112 |
ofs << " <CODE>0" << endl; |
| 113 |
ofs << " <SEVERITY>INFO" << endl; |
| 114 |
ofs << " </STATUS>" << endl; |
| 115 |
ofs << " <DTSERVER>" << beginDate.c_str() << endl; |
| 116 |
|
| 117 |
ofs << " <LANGUAGE>JPN" << endl; |
| 118 |
ofs << " <FI>" << endl; |
| 119 |
ofs << " <ORG>" << card->getIdent() << endl; |
| 120 |
ofs << " </FI>" << endl; |
| 121 |
ofs << "</SONRS>" << endl; |
| 122 |
ofs << "</SIGNONMSGSRSV1>" << endl; |
| 123 |
|
| 124 |
/* ��������(�o���N���b�Z�[�W���X�|���X) */ |
| 125 |
ofs << "<BANKMSGSRSV1>" << endl; |
| 126 |
|
| 127 |
/* �a�������^������������ */ |
| 128 |
ofs << "<STMTTRNRS>" << endl; |
| 129 |
ofs << "<TRNUID>0" << endl; |
| 130 |
ofs << "<STATUS>" << endl; |
| 131 |
ofs << " <CODE>0" << endl; |
| 132 |
ofs << " <SEVERITY>INFO" << endl; |
| 133 |
ofs << "</STATUS>" << endl; |
| 134 |
|
| 135 |
ofs << "<STMTRS>" << endl; |
| 136 |
ofs << " <CURDEF>JPY" << endl; |
| 137 |
|
| 138 |
ofs << " <BANKACCTFROM>" << endl; |
| 139 |
ofs << " <BANKID>" << card->getIdent() << endl; |
| 140 |
ofs << " <BRANCHID>" << "000" << endl; |
| 141 |
ofs << " <ACCTID>" << card->getCardId() << endl; |
| 142 |
ofs << " <ACCTTYPE>SAVINGS" << endl; |
| 143 |
ofs << " </BANKACCTFROM>" << endl; |
| 144 |
|
| 145 |
/* ���������J�n(�o���N�g�����U�N�V�������X�g) */ |
| 146 |
ofs << " <BANKTRANLIST>" << endl; |
| 147 |
ofs << " <DTSTART>" << beginDate.c_str() << endl; |
| 148 |
ofs << " <DTEND>" << endDate.c_str() << endl; |
| 149 |
|
| 150 |
/* �g�����U�N�V���� */ |
| 151 |
vector<Transaction*>::iterator it; |
| 152 |
|
| 153 |
for (it = card->begin(); it != card->end(); it++) { |
| 154 |
Transaction *t = *it; |
| 155 |
|
| 156 |
ofs << " <STMTTRN>" << endl; |
| 157 |
ofs << " <TRNTYPE>" << t->GetTrnTypeStr() << endl; |
| 158 |
ofs << " <DTPOSTED>" << dateStr(t->date).c_str() << endl; |
| 159 |
ofs << " <TRNAMT>" << t->value << endl; |
| 160 |
|
| 161 |
ofs << " <FITID>" << transIdStr(t).c_str() << endl; |
| 162 |
|
| 163 |
ofs << " <NAME>" << t->desc.c_str() << endl; |
| 164 |
if (!t->memo.IsEmpty()) { |
| 165 |
ofs << " <MEMO>" << t->memo.c_str() << endl; |
| 166 |
} |
| 167 |
ofs << " </STMTTRN>" << endl; |
| 168 |
}; |
| 169 |
|
| 170 |
ofs << " </BANKTRANLIST>" << endl; |
| 171 |
|
| 172 |
/* �c�� */ |
| 173 |
ofs << " <LEDGERBAL>" << endl; |
| 174 |
ofs << " <BALAMT>" << (*last)->balance << endl; |
| 175 |
ofs << " <DTASOF>" << endDate.c_str() << endl; |
| 176 |
ofs << " </LEDGERBAL>" << endl; |
| 177 |
|
| 178 |
/* OFX �I�� */ |
| 179 |
ofs << " </STMTRS>" << endl; |
| 180 |
ofs << "</STMTTRNRS>" << endl; |
| 181 |
ofs << "</BANKMSGSRSV1>" << endl; |
| 182 |
ofs << "</OFX>" << endl; |
| 183 |
} |
| 184 |
|
| 185 |
AnsiString Converter::dateStr(const DateTime & dt) |
| 186 |
{ |
| 187 |
AnsiString str; |
| 188 |
|
| 189 |
/* Y M D H M S */ |
| 190 |
str.sprintf("%4d%02d%02d%02d%02d%02d[+9:JST]", |
| 191 |
dt.year, dt.month, dt.date, |
| 192 |
dt.hour, dt.minutes, dt.seconds); |
| 193 |
return str; |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
@brief �g�����U�N�V����ID������ |
| 198 |
@param[in] t �g�����U�N�V���� |
| 199 |
@out �g�����U�N�V����ID |
| 200 |
|
| 201 |
���t���g�����U�N�V����ID �������������������� |
| 202 |
*/ |
| 203 |
AnsiString Converter::transIdStr(const Transaction *t) |
| 204 |
{ |
| 205 |
AnsiString str; |
| 206 |
|
| 207 |
str.sprintf("%04d%02d%02d%07d", |
| 208 |
t->date.year, t->date.month, t->date.date, t->id); |
| 209 |
return str; |
| 210 |
} |
| 211 |
|
| 212 |
|