// ************************************************************************************************************
// Author: Marcin Załęczny
// Release Date: 2010-11-10
// Licence: The GNU Lesser General Public License, version 3.0 (LGPLv3)
// ************************************************************************************************************
#include "mzTransferForm.h"


CTransferForm::CTransferForm(INT type, CString receiver, CString receiver2, CString receiverAccount, CString amount,
                     CString senderAccount, CString sender, CString sender2,
                     CString title, CString title2) {
    this->_commonInit();
    this->type = type;
    this->receiver = receiver;
    this->receiver2 = receiver2;
    this->receiverAccount = receiverAccount;
    this->receiverBank = COMMON_EMPTY_STRING;
    
    this->amount = amount;

    this->sender = sender;
    this->sender2 = sender2;
    this->senderAccount = senderAccount;
    
    this->title = title;
    this->title2 = title2;
    this->kasPlanSymbol = COMMON_EMPTY_STRING;
    
    this->amountByWords = COMMON_EMPTY_STRING;
}

CTransferForm::CTransferForm(INT type, CString receiver, CString receiver2, CString receiverAccount, CString receiverBank,
                        CString amount, CString senderAccount, CString sender, CString sender2,
                        CString title, CString title2, CString kasPlanSymbol, CString amountByWords) {
    this->_commonInit();
    this->type = type;
    this->receiver = receiver;
    this->receiver2 = receiver2;
    this->receiverAccount = receiverAccount;
    this->receiverBank = receiverBank;
    
    this->amount = amount;

    this->sender = sender;
    this->sender2 = sender2;
    this->senderAccount = senderAccount;
    
    this->title = title;
    this->title2 = title2;
    this->kasPlanSymbol = kasPlanSymbol;
    
    this->amountByWords = amountByWords;;
}

CTransferForm::~CTransferForm() {
}

CString CTransferForm::toXmlString() {
    CString transferData;
    CString value;
    
    transferData = CString(L"<transfer>\n") +
                   L"    <type>"            +   this->type                + L"</type>\n";
                   
                   value = this->receiver;
                   value.replace(L'\n', L'|');
                   transferData += CString(L"    <receiver>") + value + L"</receiver>\n";
                   
                   value = this->receiver2;
                   value.replace(L'\n', L'|');
                   transferData += CString(L"    <receiver2>") + value + L"</receiver2>\n";
                   
                   transferData += CString(L"    <receiverAccount>") + this->receiverAccount + L"</receiverAccount>\n" +
                   L"    <receiverBank>"    +   this->receiverBank        + L"</receiverBank>\n" +
                   L"    <amount>"          +   this->amount              + L"</amount>\n" +
                   L"    <senderAccount>"   +   this->senderAccount       + L"</senderAccount>\n";
                   
                   value = this->sender;
                   value.replace(L'\n', L'|');
                   transferData += CString(L"    <sender>") + value + L"</sender>\n";
                   
                   value = this->sender2;
                   value.replace(L'\n', L'|');
                   transferData += CString(L"    <sender2>") + value + L"</sender2>\n";
                   
                   value = this->title;
                   value.replace(L'\n', L'|');
                   transferData += CString(L"    <title>") + value + L"</title>\n";
                   
                   value = this->title2;
                   value.replace(L'\n', L'|');
                   transferData += CString(L"    <title2>") + value + L"</title2>\n";

                   transferData += CString(L"    <kasPlanSymbol>") + this->kasPlanSymbol + L"</kasPlanSymbol>\n" +
                   L"    <amountByWords>"   +   this->amountByWords       + L"</amountByWords>\n" +
                   L"</transfer>";
                   
    return transferData;
}

VOID CTransferForm::initFromXmlString(WCHAR* data) {
    CString xmlData(data);
    LONG pos, pos2;
    CString value;
    
    pos = xmlData.strpos(L"<type>") + wcslen(L"<type>");
    pos2 = xmlData.strpos(L"</type>", pos);
    value = xmlData.substr(pos, pos2 - pos);
    this->type = value.toInt();
    
    pos = xmlData.strpos(L"<receiver>") + wcslen(L"<receiver>");
    pos2 = xmlData.strpos(L"</receiver>", pos);
    value = xmlData.substr(pos, pos2 - pos);
    value.replace(L'|', L'\n');
    this->receiver = value;
    
    pos = xmlData.strpos(L"<receiver2>") + wcslen(L"<receiver2>");
    pos2 = xmlData.strpos(L"</receiver2>", pos);
    value = xmlData.substr(pos, pos2 - pos);
    value.replace(L'|', L'\n');
    this->receiver2 = value;
    
    pos = xmlData.strpos(L"<receiverAccount>") + wcslen(L"<receiverAccount>");
    pos2 = xmlData.strpos(L"</receiverAccount>", pos);
    value = xmlData.substr(pos, pos2 - pos);
    value.replace(L'|', L'\n');
    this->receiverAccount = value;
    
    pos = xmlData.strpos(L"<receiverBank>") + wcslen(L"<receiverBank>");
    pos2 = xmlData.strpos(L"</receiverBank>", pos);
    value = xmlData.substr(pos, pos2 - pos);
    value.replace(L'|', L'\n');
    this->receiverBank = value;
    
    pos = xmlData.strpos(L"<amount>") + wcslen(L"<amount>");
    pos2 = xmlData.strpos(L"</amount>", pos);
    value = xmlData.substr(pos, pos2 - pos);
    value.replace(L'|', L'\n');
    this->amount = value;
    
    pos = xmlData.strpos(L"<senderAccount>") + wcslen(L"<senderAccount>");
    pos2 = xmlData.strpos(L"</senderAccount>", pos);
    value = xmlData.substr(pos, pos2 - pos);
    value.replace(L'|', L'\n');
    this->senderAccount = value;
    
    pos = xmlData.strpos(L"<sender>") + wcslen(L"<sender>");
    pos2 = xmlData.strpos(L"</sender>", pos);
    value = xmlData.substr(pos, pos2 - pos);
    value.replace(L'|', L'\n');
    this->sender = value;
    
    pos = xmlData.strpos(L"<sender2>") + wcslen(L"<sender2>");
    pos2 = xmlData.strpos(L"</sender2>", pos);
    value = xmlData.substr(pos, pos2 - pos);
    value.replace(L'|', L'\n');
    this->sender2 = value;
    
    pos = xmlData.strpos(L"<title>") + wcslen(L"<title>");
    pos2 = xmlData.strpos(L"</title>", pos);
    value = xmlData.substr(pos, pos2 - pos);
    value.replace(L'|', L'\n');
    this->title = value;
    
    pos = xmlData.strpos(L"<title2>") + wcslen(L"<title2>");
    pos2 = xmlData.strpos(L"</title2>", pos);
    value = xmlData.substr(pos, pos2 - pos);
    value.replace(L'|', L'\n');
    this->title2 = value;
    
    pos = xmlData.strpos(L"<kasPlanSymbol>") + wcslen(L"<kasPlanSymbol>");
    pos2 = xmlData.strpos(L"</kasPlanSymbol>", pos);
    value = xmlData.substr(pos, pos2 - pos);
    value.replace(L'|', L'\n');
    this->kasPlanSymbol = value;
    
    pos = xmlData.strpos(L"<amountByWords>") + wcslen(L"<amountByWords>");
    pos2 = xmlData.strpos(L"</amountByWords>", pos);
    value = xmlData.substr(pos, pos2 - pos);
    value.replace(L'|', L'\n');
    this->amountByWords = value;
}

VOID CTransferForm::_commonInit() {
    this->setRealClassName(L"CTransferForm");
}

