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