001/* Copyright (C) 2014 konik.io 002 * 003 * This file is part of the Konik library. 004 * 005 * The Konik library is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * The Konik library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with the Konik library. If not, see <http://www.gnu.org/licenses/>. 017 */ 018package io.konik.zugferd.entity; 019 020import io.konik.jaxb.adapter.TwoDigitRoundingAdapter; 021import io.konik.jaxb.bindable.unqualified.PercentRoundingAdapter; 022import io.konik.validator.annotation.Comfort; 023import io.konik.validator.annotation.Extended; 024import io.konik.zugferd.unqualified.Amount; 025import io.konik.zugferd.unqualified.Indicator; 026import io.konik.zugferd.unqualified.Quantity; 027 028import javax.validation.Valid; 029import javax.validation.constraints.NotNull; 030import javax.xml.bind.annotation.XmlElement; 031import javax.xml.bind.annotation.XmlType; 032import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; 033import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 034import java.math.BigDecimal; 035 036import static io.konik.zugferd.unqualified.Indicator.falseIndicator; 037import static io.konik.zugferd.unqualified.Indicator.trueIndicator; 038 039/** 040 * 041 * = The Specified Allowance Charge. 042 */ 043@XmlType(name = "", propOrder = { "surcharge", "sequence", "calculationPercent", "basis", "basisQuantity", "actual", "reasonCode", "reason", "category" }) 044 045public class SpecifiedAllowanceCharge implements CommonAllowanceCharge { 046 047 @XmlElement(name = "ChargeIndicator") 048 private Indicator surcharge; 049 050 @XmlElement(name = "SequenceNumeric") 051 private BigDecimal sequence; 052 053 @XmlElement(name = "CalculationPercent") 054 @XmlJavaTypeAdapter(PercentRoundingAdapter.class) 055 private BigDecimal calculationPercent; 056 057 @XmlElement(name = "BasisAmount") 058 @XmlJavaTypeAdapter(TwoDigitRoundingAdapter.class) 059 private Amount basis; 060 061 @XmlElement(name = "BasisQuantity") 062 private Quantity basisQuantity; 063 064 @XmlElement(name = "ActualAmount") 065 @XmlJavaTypeAdapter(TwoDigitRoundingAdapter.class) 066 private Amount actual; 067 068 @XmlElement(name = "ReasonCode") 069 @XmlJavaTypeAdapter(CollapsedStringAdapter.class) 070 private String reasonCode; 071 072 @XmlElement(name = "Reason") 073 private String reason; 074 075 @XmlElement(name = "CategoryTradeTax") 076 private AppliedTax category; 077 078 /** 079 * Instantiates a new allowance charge. 080 */ 081 public SpecifiedAllowanceCharge() { 082 surcharge = Indicator.falseIndicator(); 083 } 084 085 /** 086 * Checks if is a surcharge. 087 * 088 * @return true if charge 089 */ 090 @Override 091 @NotNull(groups = Comfort.class) 092 public boolean isSurcharge() { 093 return surcharge.getIndicator(); 094 } 095 096 /** 097 * Checks if is discount. 098 * 099 * @return true if is discount 100 */ 101 @Override 102 @NotNull(groups = Comfort.class) 103 public boolean isDiscount() { 104 return !surcharge.getIndicator(); 105 } 106 107 /** 108 * Sets amount to be a surcharge. 109 * 110 * @return the allowance charge to be true 111 */ 112 @Override 113 public SpecifiedAllowanceCharge setSurcharge() { 114 this.surcharge = trueIndicator(); 115 return this; 116 } 117 118 /** 119 * Sets the amount to be a discount. 120 * 121 * @return the allowance discount to be true 122 */ 123 @Override 124 public SpecifiedAllowanceCharge setDiscount() { 125 this.surcharge = falseIndicator(); 126 return this; 127 } 128 129 /** 130 * Gets the sequence number of the allowance charge 131 * 132 * @return the sequence 133 */ 134 @Override 135 @Extended 136 public BigDecimal getSequence() { 137 return sequence; 138 } 139 140 /** 141 * Sets the sequence number of the allowance charge. 142 * 143 * @param sequence the new sequence 144 * @return the allowance charge 145 */ 146 @Override 147 public SpecifiedAllowanceCharge setSequence(BigDecimal sequence) { 148 this.sequence = sequence; 149 return this; 150 } 151 152 /** 153 * Gets the calculation percent of the allowance charge 154 * 155 * @return the calculation percent 156 */ 157 @Override 158 @Extended 159 public BigDecimal getCalculationPercent() { 160 return calculationPercent; 161 } 162 163 /** 164 * Sets the calculation percent of the allowance charge. 165 * 166 * @param calculationPercent the new calculation percent 167 * @return the allowance charge 168 */ 169 @Override 170 public SpecifiedAllowanceCharge setCalculationPercent(BigDecimal calculationPercent) { 171 this.calculationPercent = calculationPercent; 172 return this; 173 } 174 175 /** 176 * Gets the basis amount of the allowance charge. 177 * 178 * @return the basis amount 179 */ 180 @Override 181 @Valid 182 @Extended 183 public Amount getBasis() { 184 return basis; 185 } 186 187 /** 188 * Sets the basis amount of the allowance charge. 189 * 190 * @param basisAmount the new basis amount 191 * @return the allowance charge 192 */ 193 @Override 194 public SpecifiedAllowanceCharge setBasis(Amount basisAmount) { 195 this.basis = basisAmount; 196 return this; 197 } 198 199 /** 200 * Gets the basis quantity. 201 * 202 * @return the basis quantity 203 */ 204 @Override 205 @Extended 206 @Valid 207 public Quantity getBasisQuantity() { 208 return basisQuantity; 209 } 210 211 /** 212 * Sets the basis quantity. 213 * 214 * @param basisQuantity the new basis quantity 215 * @return the allowance charge 216 */ 217 @Override 218 public SpecifiedAllowanceCharge setBasisQuantity(Quantity basisQuantity) { 219 this.basisQuantity = basisQuantity; 220 return this; 221 } 222 223 /** 224 * Gets the actual amount. 225 * 226 * @return the actual amount 227 */ 228 @Override 229 @Valid 230 @NotNull(groups = Comfort.class) 231 public Amount getActual() { 232 return actual; 233 } 234 235 /** 236 * Sets the actual amount. 237 * 238 * @param actualAmount the new actual amount 239 * @return the allowance charge 240 */ 241 @Override 242 public SpecifiedAllowanceCharge setActual(Amount actualAmount) { 243 this.actual = actualAmount; 244 return this; 245 } 246 247 /** 248 * Gets the reason code for the reason content. 249 * 250 * @return the reason code 251 */ 252 @Override 253 @Extended 254 public String getReasonCode() { 255 return reasonCode; 256 } 257 258 /** 259 * Sets the reason code for the reason content. 260 * 261 * @param reasonCode the new reason code 262 * @return the allowance charge 263 */ 264 @Override 265 public SpecifiedAllowanceCharge setReasonCode(String reasonCode) { 266 this.reasonCode = reasonCode; 267 return this; 268 } 269 270 /** 271 * Gets the reason free text 272 * 273 * @return the reason 274 */ 275 @Override 276 @Comfort 277 public String getReason() { 278 return reason; 279 } 280 281 /** 282 * Sets the reason free text 283 * 284 * @param reason the new reason 285 * @return the allowance charge 286 */ 287 @Override 288 public SpecifiedAllowanceCharge setReason(String reason) { 289 this.reason = reason; 290 return this; 291 } 292 /** 293 * Gets the category. 294 * 295 * @return the category 296 */ 297 @Comfort 298 public AppliedTax getCategory() { 299 return category; 300 } 301 302 /** 303 * Sets the category. 304 * 305 * @param category the new category 306 * @return the allowance charge 307 */ 308 public SpecifiedAllowanceCharge setCategory(AppliedTax category) { 309 this.category = category; 310 return this; 311 } 312 313}