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; 022import io.konik.jaxb.adapter.AmountHighRoundingAdapter; 023import io.konik.jaxb.bindable.unqualified.PercentRoundingAdapter; 024import io.konik.validator.annotation.Comfort; 025import io.konik.zugferd.unqualified.Amount; 026import io.konik.zugferd.unqualified.Indicator; 027import io.konik.zugferd.unqualified.Quantity; 028 029import java.math.BigDecimal; 030 031import javax.validation.Valid; 032import javax.validation.constraints.NotNull; 033import javax.xml.bind.annotation.XmlElement; 034import javax.xml.bind.annotation.XmlType; 035import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; 036import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 037 038/** 039 * = The Allowance Charge 040 * 041 * Represents trade surcharges and discounts as well as a reason. 042 */ 043@XmlType(name = "TradeAllowanceChargeType", propOrder = { "surcharge", "sequence", "calculationPercent", "basis", 044 "basisQuantity", "actual", "reasonCode", "reason" }) 045public class AllowanceCharge { 046 047 @XmlElement(name = "ChargeIndicator") 048 @NotNull(groups = Comfort.class) 049 private Indicator surcharge; 050 051 @XmlElement(name = "SequenceNumeric") 052 private BigDecimal sequence; 053 054 @XmlElement(name = "CalculationPercent") 055 @XmlJavaTypeAdapter(PercentRoundingAdapter.class) 056 private BigDecimal calculationPercent; 057 058 @Valid 059 @XmlElement(name = "BasisAmount") 060 @XmlJavaTypeAdapter(value = AmountHighRoundingAdapter.class) 061 private Amount basis; 062 063 @Valid 064 @XmlElement(name = "BasisQuantity") 065 private Quantity basisQuantity; 066 067 @Valid 068 @NotNull(groups = Comfort.class) 069 @XmlElement(name = "ActualAmount") 070 @XmlJavaTypeAdapter(value = AmountHighRoundingAdapter.class) 071 private Amount actual; 072 073 @XmlElement(name = "ReasonCode") 074 @XmlJavaTypeAdapter(CollapsedStringAdapter.class) 075 private String reasonCode; 076 077 @XmlElement(name = "Reason") 078 private String reason; 079 080 /** 081 * Instantiates a new allowance charge. 082 */ 083 public AllowanceCharge() { 084 surcharge = Indicator.falseIndicator(); 085 } 086 087 /** 088 * Checks if is a surcharge. 089 * 090 * @return true if charge otherwise discount 091 */ 092 public boolean isSurcharge() { 093 return surcharge.getIndicator(); 094 } 095 096 /** 097 * Checks if is discount. 098 * 099 * @return true if discount otherwise charge 100 */ 101 public boolean isDiscount() { 102 return !surcharge.getIndicator(); 103 } 104 105 /** 106 * Sets amount to be a surcharge. 107 * 108 * @return the allowance charge 109 */ 110 public AllowanceCharge setSurcharge() { 111 this.surcharge = trueIndicator(); 112 return this; 113 } 114 115 /** 116 * Sets the amount to be a discount. 117 * 118 * @return the allowance charge 119 */ 120 public AllowanceCharge setDiscount() { 121 this.surcharge = falseIndicator(); 122 return this; 123 } 124 125 /** 126 * Gets the sequence. 127 * 128 * @return the sequence 129 */ 130 public BigDecimal getSequence() { 131 return sequence; 132 } 133 134 /** 135 * Sets the sequence. 136 * 137 * @param sequence the new sequence 138 */ 139 public void setSequence(BigDecimal sequence) { 140 this.sequence = sequence; 141 } 142 143 /** 144 * Gets the calculation percent. 145 * 146 * @return the calculation percent 147 */ 148 public BigDecimal getCalculationPercent() { 149 return calculationPercent; 150 } 151 152 /** 153 * Sets the calculation percent. 154 * 155 * @param calculationPercent the new calculation percent 156 */ 157 public void setCalculationPercent(BigDecimal calculationPercent) { 158 this.calculationPercent = calculationPercent; 159 } 160 161 /** 162 * Gets the basis amount. 163 * 164 * @return the basis amount 165 */ 166 public Amount getBasis() { 167 return basis; 168 } 169 170 /** 171 * Sets the basis amount. 172 * 173 * @param basisAmount the new basis amount 174 * @return the allowance charge 175 */ 176 public AllowanceCharge setBasis(Amount basisAmount) { 177 this.basis = basisAmount; 178 return this; 179 } 180 181 /** 182 * Gets the basis quantity. 183 * 184 * @return the basis quantity 185 */ 186 public Quantity getBasisQuantity() { 187 return basisQuantity; 188 } 189 190 /** 191 * Sets the basis quantity. 192 * 193 * @param basisQuantity the new basis quantity 194 */ 195 public void setBasisQuantity(Quantity basisQuantity) { 196 this.basisQuantity = basisQuantity; 197 } 198 199 /** 200 * Gets the actual amount. 201 * 202 * @return the actual amount 203 */ 204 public Amount getActual() { 205 return actual; 206 } 207 208 /** 209 * Sets the actual amount. 210 * 211 * @param actualAmount the new actual amount 212 * @return the allowance charge 213 */ 214 public AllowanceCharge setActual(Amount actualAmount) { 215 this.actual = actualAmount; 216 return this; 217 } 218 219 /** 220 * Gets the reason code. 221 * 222 * @return the reason code 223 */ 224 public String getReasonCode() { 225 return reasonCode; 226 } 227 228 /** 229 * Sets the reason code. 230 * 231 * @param reasonCode the new reason code 232 */ 233 public void setReasonCode(String reasonCode) { 234 this.reasonCode = reasonCode; 235 } 236 237 /** 238 * Gets the reason. 239 * 240 * @return the reason 241 */ 242 public String getReason() { 243 return reason; 244 } 245 246 /** 247 * Sets the reason. 248 * 249 * @param reason the new reason 250 * @return the allowance charge 251 */ 252 public AllowanceCharge setReason(String reason) { 253 this.reason = reason; 254 return this; 255 } 256 257}