File indexing completed on 2024-04-28 16:30:11
0001 /*************************************************************************** 0002 * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr 0003 * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 ***************************************************************************/ 0006 /** @file 0007 * This file defines classes SKGInterestObject. 0008 * 0009 * @author Stephane MANKOWSKI / Guillaume DE BURE 0010 */ 0011 #include "skginterestobject.h" 0012 #include "skgdocument.h" 0013 0014 SKGInterestObject::SKGInterestObject(): SKGInterestObject(nullptr) 0015 {} 0016 0017 SKGInterestObject::SKGInterestObject(SKGDocument* iDocument, int iID): SKGObjectBase(iDocument, QStringLiteral("v_interest"), iID) 0018 {} 0019 0020 SKGInterestObject::SKGInterestObject(const SKGInterestObject& iObject) 0021 = default; 0022 0023 SKGInterestObject::SKGInterestObject(const SKGObjectBase& iObject) 0024 { 0025 if (iObject.getRealTable() == QStringLiteral("interest")) { 0026 copyFrom(iObject); 0027 } else { 0028 *this = SKGObjectBase(iObject.getDocument(), QStringLiteral("v_interest"), iObject.getID()); 0029 } 0030 } 0031 0032 SKGInterestObject& SKGInterestObject::operator= (const SKGObjectBase& iObject) 0033 { 0034 copyFrom(iObject); 0035 return *this; 0036 } 0037 0038 SKGInterestObject& SKGInterestObject::operator= (const SKGInterestObject& iObject) 0039 { 0040 copyFrom(iObject); 0041 return *this; 0042 } 0043 0044 SKGInterestObject::~SKGInterestObject() 0045 = default; 0046 0047 SKGError SKGInterestObject::setRate(double iValue) 0048 { 0049 return setAttribute(QStringLiteral("f_rate"), SKGServices::doubleToString(iValue)); 0050 } 0051 0052 double SKGInterestObject::getRate() const 0053 { 0054 return SKGServices::stringToDouble(getAttribute(QStringLiteral("f_rate"))); 0055 } 0056 0057 SKGError SKGInterestObject::setDate(QDate iDate) 0058 { 0059 return setAttribute(QStringLiteral("d_date"), SKGServices::dateToSqlString(iDate)); 0060 } 0061 0062 QDate SKGInterestObject::getDate() const 0063 { 0064 return SKGServices::stringToTime(getAttribute(QStringLiteral("d_date"))).date(); 0065 } 0066 0067 SKGError SKGInterestObject::setIncomeValueDateMode(SKGInterestObject::ValueDateMode iMode) 0068 { 0069 return setAttribute(QStringLiteral("t_income_value_date_mode"), (iMode == FIFTEEN ? QStringLiteral("F") : SKGServices::intToString(static_cast<int>(iMode) - 1))); 0070 } 0071 0072 SKGInterestObject::ValueDateMode SKGInterestObject::getIncomeValueDateMode() const 0073 { 0074 QString mode = getAttribute(QStringLiteral("t_income_value_date_mode")); 0075 return (mode == QStringLiteral("F") ? FIFTEEN : static_cast<SKGInterestObject::ValueDateMode>(SKGServices::stringToInt(mode) + 1)); 0076 } 0077 0078 SKGError SKGInterestObject::setExpenditueValueDateMode(SKGInterestObject::ValueDateMode iMode) 0079 { 0080 return setAttribute(QStringLiteral("t_expenditure_value_date_mode"), (iMode == FIFTEEN ? QStringLiteral("F") : SKGServices::intToString(static_cast<int>(iMode) - 1))); 0081 } 0082 0083 SKGInterestObject::ValueDateMode SKGInterestObject::getExpenditueValueDateMode() const 0084 { 0085 QString mode = getAttribute(QStringLiteral("t_expenditure_value_date_mode")); 0086 return (mode == QStringLiteral("F") ? FIFTEEN : static_cast<SKGInterestObject::ValueDateMode>(SKGServices::stringToInt(mode) + 1)); 0087 } 0088 0089 SKGError SKGInterestObject::setInterestComputationMode(SKGInterestObject::InterestMode iMode) 0090 { 0091 return setAttribute(QStringLiteral("t_base"), 0092 (iMode == FIFTEEN24 ? QStringLiteral("24") : 0093 (iMode == DAYS360 ? QStringLiteral("360") : 0094 QStringLiteral("365")))); 0095 } 0096 0097 SKGInterestObject::InterestMode SKGInterestObject::getInterestComputationMode() const 0098 { 0099 QString mode = getAttribute(QStringLiteral("t_base")); 0100 return (mode == QStringLiteral("24") ? FIFTEEN24 : (mode == QStringLiteral("360") ? DAYS360 : DAYS365)); 0101 } 0102 0103 QString SKGInterestObject::getWhereclauseId() const 0104 { 0105 // Could we use the id 0106 QString output = SKGObjectBase::getWhereclauseId(); 0107 if (output.isEmpty()) { 0108 // No, so we use the date and parent 0109 if (!(getAttribute(QStringLiteral("d_date")).isEmpty()) && !(getAttribute(QStringLiteral("rd_account_id")).isEmpty())) { 0110 output = "d_date='" % getAttribute(QStringLiteral("d_date")) % "' AND rd_account_id=" % getAttribute(QStringLiteral("rd_account_id")); 0111 } 0112 } 0113 return output; 0114 } 0115 0116 SKGError SKGInterestObject::setAccount(const SKGAccountObject& iAccount) 0117 { 0118 return setAttribute(QStringLiteral("rd_account_id"), SKGServices::intToString(iAccount.getID())); 0119 } 0120 0121 SKGError SKGInterestObject::getAccount(SKGAccountObject& oAccount) const 0122 { 0123 SKGError err = getDocument()->getObject(QStringLiteral("v_account"), "id=" % getAttribute(QStringLiteral("rd_account_id")), oAccount); 0124 return err; 0125 } 0126 0127