1 /*************************************************************************** 2 * SPDX-FileCopyrightText: 2021 S. MANKOWSKI stephane@mankowski.fr 3 * SPDX-FileCopyrightText: 2021 G. DE BURE support@mankowski.fr 4 * SPDX-License-Identifier: GPL-3.0-or-later 5 ***************************************************************************/ 6 #ifndef SKGRECURRENTOPERATIONOBJECT_H 7 #define SKGRECURRENTOPERATIONOBJECT_H 8 /** @file 9 * This file defines classes SKGRecurrentOperationObject. 10 * 11 * @author Stephane MANKOWSKI / Guillaume DE BURE 12 */ 13 14 #include "skgbankmodeler_export.h" 15 #include "skgobjectbase.h" 16 class SKGOperationObject; 17 class SKGDocumentBank; 18 19 /** 20 * This class manages recurrent operation object 21 */ 22 class SKGBANKMODELER_EXPORT SKGRecurrentOperationObject final : public SKGObjectBase 23 { 24 public: 25 /** 26 * This enumerate defines the period unit 27 */ 28 enum PeriodUnit {DAY = 0, /**< day */ 29 WEEK = 1, /**< week */ 30 MONTH = 2, /**< month */ 31 YEAR = 3 /**< year */ 32 }; 33 /** 34 * This enumerate defines the period unit 35 */ 36 Q_ENUM(PeriodUnit) 37 38 /** 39 * Default constructor 40 */ 41 explicit SKGRecurrentOperationObject(); 42 43 /** 44 * Constructor 45 * @param iDocument the document containing the object 46 * @param iID the identifier in @p iTable of the object 47 */ 48 explicit SKGRecurrentOperationObject(SKGDocument* iDocument, int iID = 0); 49 50 /** 51 * Copy constructor 52 * @param iObject the object to copy 53 */ 54 explicit SKGRecurrentOperationObject(const SKGObjectBase& iObject); 55 56 /** 57 * Copy constructor 58 * @param iObject the object to copy 59 */ 60 SKGRecurrentOperationObject(const SKGRecurrentOperationObject& iObject); 61 62 /** 63 * Operator affectation 64 * @param iObject the object to copy 65 */ 66 SKGRecurrentOperationObject& operator= (const SKGObjectBase& iObject); 67 68 /** 69 * Operator affectation 70 * @param iObject the object to copy 71 */ 72 SKGRecurrentOperationObject& operator= (const SKGRecurrentOperationObject& iObject); 73 74 /** 75 * Destructor 76 */ 77 virtual ~SKGRecurrentOperationObject(); 78 79 /** 80 * Get the parent operation 81 * @param oOperation the parent operation 82 * @return an object managing the error. 83 * @see SKGError 84 */ 85 SKGError getParentOperation(SKGOperationObject& oOperation) const; 86 87 /** 88 * Set the parent operation 89 * @param iOperation the parent operation 90 * @return an object managing the error. 91 * @see SKGError 92 */ 93 SKGError setParentOperation(const SKGOperationObject& iOperation); 94 95 /** 96 * Set the increment 97 * @param iIncrement the number of @see setPeriodUnit 98 * @return an object managing the error 99 * @see SKGError 100 */ 101 SKGError setPeriodIncrement(int iIncrement); 102 103 /** 104 * Get the increment 105 * @return the number 106 */ 107 int getPeriodIncrement() const; 108 109 /** 110 * Get the period unit of this recurrent operation 111 * @return the status 112 */ 113 SKGRecurrentOperationObject::PeriodUnit getPeriodUnit() const; 114 115 /** 116 * Set the period unit of this recurrent operation 117 * @param iPeriod the period unit 118 * @return an object managing the error 119 * @see SKGError 120 */ 121 SKGError setPeriodUnit(SKGRecurrentOperationObject::PeriodUnit iPeriod); 122 123 /** 124 * Set the number of days before term to create operation 125 * @param iDays the number of days 126 * @return an object managing the error 127 * @see SKGError 128 */ 129 SKGError setAutoWriteDays(int iDays); 130 131 /** 132 * Get the number of days before term to create operation 133 * @return the number of days 134 */ 135 int getAutoWriteDays() const; 136 137 /** 138 * Set the number of days before term to warn user 139 * @param iDays the number of days 140 * @return an object managing the error 141 * @see SKGError 142 */ 143 SKGError setWarnDays(int iDays); 144 145 /** 146 * Get the number of days before term to warn user 147 * @return the number of days 148 */ 149 int getWarnDays() const; 150 151 /** 152 * Set date of this recurrent operation 153 * @param iDate the date 154 * @return an object managing the error 155 * @see SKGError 156 */ 157 // cppcheck-suppress passedByValue 158 SKGError setDate(QDate iDate); 159 160 /** 161 * Get date of this recurrent operation 162 * @return the date 163 */ 164 QDate getDate() const; 165 166 /** 167 * Get next date of this recurrent operation 168 * @return the date 169 */ 170 QDate getNextDate() const; 171 172 /** 173 * Get all operations created by this recurrent operation 174 * @param oOperations all operations 175 * @return an object managing the error 176 * @see SKGError 177 */ 178 SKGError getRecurredOperations(SKGListSKGObjectBase& oOperations) const; 179 180 /** 181 * To warn or not the end user 182 * @param iWarn the warn: true or false 183 * @return an object managing the error 184 * @see SKGError 185 */ 186 SKGError warnEnabled(bool iWarn); 187 188 /** 189 * To know if the end user is warned or not 190 * @return an object managing the error 191 * @see SKGError 192 */ 193 bool isWarnEnabled() const; 194 195 /** 196 * To activate or not the auto write mode 197 * @param iAutoWrite auto write mode: true or false 198 * @return an object managing the error 199 * @see SKGError 200 */ 201 SKGError autoWriteEnabled(bool iAutoWrite); 202 203 /** 204 * To know if auto write mode is enabled or not 205 * @return an object managing the error 206 * @see SKGError 207 */ 208 bool isAutoWriteEnabled() const; 209 210 /** 211 * To know if a time limit is enabled or not 212 * @return an object managing the error 213 * @see SKGError 214 */ 215 bool hasTimeLimit() const; 216 217 /** 218 * To enable / disable a time limit 219 * @param iTimeLimit the time limit: true or false 220 * @return an object managing the error 221 * @see SKGError 222 */ 223 SKGError timeLimit(bool iTimeLimit); 224 225 /** 226 * Set the time limit 227 * @param iTimeLimit the number of times operation will be inserted 228 * @return an object managing the error 229 * @see SKGError 230 */ 231 SKGError setTimeLimit(int iTimeLimit); 232 233 /** 234 * Set the time limit 235 * @param iLastDate the last date of the operation will be inserted. setDate, setPeriodIncrement and setPeriodUnit must be used before. 236 * @return an object managing the error 237 * @see SKGError 238 */ 239 // cppcheck-suppress passedByValue 240 SKGError setTimeLimit(QDate iLastDate); 241 242 /** 243 * Get the number of times operation will be inserted 244 * @return the number of times 245 */ 246 int getTimeLimit() const; 247 248 /** 249 * Warn and/or create operations for this recurrent operation 250 * @param oNbInserted number of operations inserted 251 * @param iForce to force the insertion even if autowrite is not enable 252 * @param iDate date limit for insertion 253 * @return an object managing the error 254 * @see SKGError 255 */ 256 // cppcheck-suppress passedByValue 257 SKGError process(int& oNbInserted, bool iForce = false, QDate iDate = QDate::currentDate()); 258 259 /** 260 * Warn and/or create operations for all recurrent operations of the document 261 * @param iDocument the document containing the object 262 * @param oNbInserted number of operations inserted 263 * @param iForce to force the insertion even if autowrite is not enable* 264 * @param iDate date limit for insertion 265 * @return an object managing the error 266 * @see SKGError 267 */ 268 // cppcheck-suppress passedByValue 269 static SKGError process(SKGDocumentBank* iDocument, int& oNbInserted, bool iForce = false, QDate iDate = QDate::currentDate()); 270 }; 271 /** 272 * Declare the class 273 */ 274 Q_DECLARE_TYPEINFO(SKGRecurrentOperationObject, Q_MOVABLE_TYPE); 275 #endif 276